R Studio, and Presentations, and Git! Oh my!

I have been using R for many years now and it has served me quite well. I have used it for all manners of data prep work, analysis, developing figures, and more recently GIS and creating reproducible reports with knitr. During this time my typical workflow included creating new folders for projects, throwing in an R shortcut that opens in the project folder directory and developing my scripts and functions with Notepad ++ (used to be TINN-R). As I was using mostly R, some LaTeX, and some Python, Notepad ++ seemed to be a good fit. I had seen a few other folks in the office using R Studio, but wasn’t interested in making the switch.

So, fast forward several months. I am now more active on Twitter (@jhollist, if you are interested) and have started this blog. As a result, I am much more aware of the general goings on in the R world (HT @Rstudioapp, @ropensci, @hadleywickham, @rbloggers just to name a few). This has made me aware of the many cool things getting developed by the R Studio crew. Two that really caught my eye were Shiny and R Presentations.

Also during this time, I have been reading up on using Markdown and version control for collaborative writing (i.e. see Inundata and associated publications). The combination of these pointed towards giving R Studio and Git a try. What follows is a very abbreviated account of my experience and a few hints to get up and running.

Get a Github account: If you don’t have one already, head over to Github and set up an account.

Install the preview version of R Studio (at least its a preview as of the date of this post): The currently available R Studio Preview version is 0.98.456. Why is this interesting? Well, you can create R Presentations with it.

Start a version controlled project and connect it to your Github account: First, create a new repository on Github. When that is created copy the https URL for the repository. Second, create a new project in R Studio, selecting the “Create Project From: Version Control”. Choose “Git” as the version control and in the “Repository URL” field put the https URL of your newly created Github repository. You should be able to commit locally and push to your master branch on Github.

Create a presentation: Now all you need to do is read up on some of the basics of R Markdown for presentations and have at it. Once written, click on the “knit html” button and save as html. Use that or push to web!

Hints:

Most of the dithering was not at all with getting the presentations built and R Studio up and running, it was with the layout. As I am an extreme novice with CSS it took me some time to get everything where I wanted. But I did eventually get it set.

First thing I had to figure out was how to get changes to the CSS implemented. From my reading I found three ways:

Edit the default style sheet: On my system, it is located at C:\Program Files\RStudio\resources\presentation\slides.css. Simply add the changes you want to the end of the file, save, and restart R Studio. Now every new presentation you start will have your slide template implemented. Couple of warnings for this. First, if you install a new version of R Studio, your customized default CSS will get overwritten. Second, and this is just good practice, save a copy of the original (or better yet, use Git to track the changes) so if you really mess up you don’t need to do a reinstall.

Use a custom style sheet: Copy the default and edit it to your liking. Once you have that finished simply throw in the following line at the top of your presentation directly under your title slide: css: mySlideTemplate.css

Add styles directly into the presentation: As knitr converts the R Markdown into html you can simply add the styles at the top of the presentation and they will get included when you knit to html. See the R Studio write up for more info.

Some of the changes I wanted to make were to set the backgrounds for all slides to white, add in a topbar on each slide and re-position the slide titles.

Two things that I tried to get working but couldn’t were more control over the positioning on some of the text (e.g. centering) and the ability to output presentations as PDF. The positioning issue is likely do to my lack of experience with Markdown. The PDF issue sounds like a common challenge with the Reveal.js based presentations. Since the R presentations are still part of the preview, this is just me being picky. I realize many of these kinds of issues will get worked out with future releases.

Verdict

So, my verdict after a month or so with R Studio… I’m hooked. I am now using it for presentations (just completed my third one) and to top it off, I am pushing those presentations up to my Github page (still in development) and presenting via the web. I have created a template for the presentations that will work for what I need at work and now it is simply a matter of plugging in the text and images for my presentations.

Presentations aside, I have only had a chance for some limited analysis with R Studio (thanks government shutdown), but the editor in general is, at a minimum, on par with everything else I have tried but likely will prove to be an improvement over what I have gotten used to.

In short R Studio has a very shallow learning curve, the integrated environment makes work easy, the interface is nice, and the options (Git, Presentations, Shiny Apps, Sweave, etc.) are fantastic. If you are thinking of making the switch, do it.