Rstudio addin to tweet from Rstudio
This was cobbled together in a few hours, so no guarantees! It works for me. If you want to fix a bug, please make a pull request.
If you installed this on or before 25 Dec 2017, you'll need to redo the authentication for twitter. See instructions below.
Have you ever wanted to...
- ...easily tweet a plot you're working on, from the RStudio interface?
- ...respond to someone on Twitter with R code example and plot, to make a point?
- ...tweet from RStudio, so you don't have to open Twitter and kill your produtivity?
You're in luck.
The package has two features (right now):
- Tweet plain text from R. Highlight text, select "Get a blog" from the RStudio addins menu (under tweetRcode), and the package will split the text, add tweet numbers (if necessary), and then tweet for you. The tweets will be properly threaded. You can add an active plot to the tweet.
- Tweet R code and plots from R. Highlight R code, select "Tweet R code" from the RStudio addins menu (under tweetRcode), and the package will run the R code and tweet your text/code along with the generated figures. Can also automatically upload a copy to a GitHub gist and link to it.
-
You'll need a recent version of RStudio for this, so that you can use RStudio addins.
-
If you want to create animated GIFs, you'll need ImageMagick installed. If you're a Windows user, you'll need to make sure you install the "legacy utilities":
-
If you want to post GitHub gists, you'll need a GitHub account.
-
You'll need to create app authentication keys for GitHub and twitter. This is easy and only needs to be done once. Instructions are below.
You can install the package with devtools
:
install.packages('devtools') # if necessary
devtools::install_github("richarddmorey/tweetRcode",
subdir = "tweetRcode")
You then need to make sure R can authenticate with GitHub (for posting gists) and twitter (for tweeting, of course).
Authenticating twitter is a bit more complicated, but not much. Follow these instructions and you'll be good to go.
If you followed the old instructions for the twitteR
package, you'll need to redo it; the new functions are based on the rtweet
package.
In order to post GitHub gists, you need to authenticate to GitHub within R.
Follow these directions to get a GitHub personal identification token (PAT).
Open the .Renviron
file that was created/appended in the steps to authenticate Twitter. On the first new line of the .Renviron
file (after everything else), add
GITHUB_PAT = YOUR_GIST_PAT_KEY
replacing YOUR_GIST_PAT_KEY
with the one you generated. Save the file.
Restart R, and type this in the R console:
Sys.getenv()[c("TWITTER_PAT","GITHUB_PAT")]
and you should see your PAT tokens.
- In RStudio, open a new text document (File -> New file -> Text file). 2. Type your tweet storm. You can force a break at a point using three or more hyphens (---) on their own line. A single tweet is fine too; you can just post a single tweet from R.
- Highlight the entire text.
- Open the Addins menu from the top of the RStudio window, and click "Get a blog" under "tweetRcode". If you've set up authentication correctly, the tweet should post automatically.
"Get a blog (configurable)" lets you edit the text and post it as a reply, if you like. It will also allow you to add an image from your active R plotting devices.
You'll need to have configured the authentications before you do this.
- Open a new R script document in Rstudio.
- Type some code that you'd like to tweet.
- Highlight the lines you want to run and tweet.
- Select "Tweet R Code" from the "Addins" menu at the top of the RStudio window.
- Select the appropriate options, and click "Done".
Depending on the options you've selected, it may take a few seconds to run the code, generate the images, and upload the tweet and gist.
-
If you want to post a reply to someone else's tweet, you'll need to mention the owner of that tweet in order to properly reply. If you don't, the tweet will be posted to your timeline (i.e., not a reply). This is a limitation of the Twitter API.
-
Replies don't seem to be tagged with anyone in the thread. You'll need to mention users explicitly if you want them to be notified that you replied.
-
rtweet: used for Twitter API calls. You can use this for much more than tweeting for R.
-
gistr: used for GitHub gist API calls.
-
animation: used for joining images into animated GIFs.
-
codefinch: RStudio addin for tweeting images of R code. Similar to tweetRcode but different in execution.
-
hrbraddins: Includes RStudio addin for Tweet storms, but with fewer features.