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

[This article was first published on Landscape Ecology 2.0 » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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.

What do you need to get up an running?

  1. Install Git:  For my setup I simply grabbed the git installer.
  2. Get a Github account: If you don’t have one already, head over to Github and set up an account.
  3. 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.
  4. 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.
  5. 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!


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:

  1. 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.
  2. 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
  3. 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.

To change the title slide background color and text color:

.section .reveal .state-background {
    background: white;}
.section .reveal h1,
.section .reveal p {
    color: black;
    position: relative;
    top: 4%;}

To add a top bar:

.reveal .present {
   background: white;
   background-image: url(http://jhollist.github.io/files/images/TopBar.jpg);
   background-repeat: no-repeat;
   background-position: 0% 9.35%;
   background-size: 100%;}

And to move the slide title but not the subsequent h3 tags:

.reveal h3{
   position: relative;
   top: 0%;
   left: 0%;}
.reveal .slideContent h3{
   left: 0%;}

What I would like to see added:

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.


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.

Lastly, apologies for the cheeky title.  My internal Kansan got the better of me.

Filed under: Open Science, Programming, R Tagged: CSS, Git, Github, R Presentations, RStudio

To leave a comment for the author, please follow the link and comment on their blog: Landscape Ecology 2.0 » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)