On occasion of the 10,000th R package on CRAN, eoda operated an automated Twitter account which regularly posted the current number of packages available on CRAN until the 10,000-package milestone has been passed on January 28, 2017.

To operate this account, we wrote an R script for reading the current number of R packages on CRAN every hour and automatically sending a Tweet with the status quo. All we needed to make this work was the Twitter API as well as the twitteR package.

For using the Twitter API, it is necessary to create a corresponding app for the Twitter account.

For this, log in with the respective account on apps.twitter.com and fill out the form under Create New App.

Einrichten einer Twitter App auf apps.twitter.com
Creating a Twitter app on apps.twitter.com

In the next window, you can set among other things the permissions of the app, “read only”, “read and write” or “read, write and access direct messages”. To operate the app, you also need the Consumer Key and Consumer Secret as well as the Access Token and Access Token Secret you can find in the tab Key and Access Tokens.

Application Settings
Application Settings
Access Token
Access Token

We transferred this information into an extra file in order to be able to load them into the R script later on. Now the app is ready for use.

For sending Tweets out of R, you need the functions setup_twitter_oauth and tweet from the twitter package. The function setup_twitter_oauth manages the authentication and tweet finally sends the appropriate Tweet.

The following R script demonstrates how we applied this to our Rstatsgoes10k account:

Good luck with the implementation.