Monday, February 25, 2013

Top 6 reasons you need to be using RStudio

Rstudio provides you with tools to make your work more productive.
New to R? -  check out these resources for getting staRted

RStudio is an awesome tool that can help you do your work better and faster.  In technical terms, RStudio is a cross-platform integrated development environment (IDE) for the R statistical language.  If you aren't a programmer type, that description may not mean much to you, and so maybe you think that means you shouldn't be using it.  In this post I will try to convince you that even (or especially) casual users of R should be using RStudio.  

Click to enlarge: Rstudio in action. 

Top 6 reasons to use RStudio

6. the joys of window docking

ever get really annoyed wondering where the hell the text file went that contains your R code? Or wonder where the plot is that you KNOW should have appeard (it was behind your web browser window ;-))? These sorts of problems are eliminated by using Rstudio because all the relevant windows are docked together.  In the image above, the source file containing your code is in the upper left....those commands appear when you run them in the R interpreter on the bottom left.  Plots and help files appear in the bottom right.  The upper right shows your graphical workspace. It is all docked together in a single application window.

5. the graphical workspace

sure, you can type ls() in the interpreter and get the following back [1] "df".  But isn't it much nicer to see a full list of objects in my workspace in the upper right panel of the Rstudio window? Now I actually know something about df, and by just clicking on an name it pops up with a graphical view of that object.....nice!

Click to enlarge: graphical view of a dataframe from the workspace

4. full-featured text editor

This includes everything you sh/would expect from a text editor: syntax highlighting, parenthesis and bracket matching, find/replace with regular expressions, etc etc. Learning how to use a good text editor makes a huge difference!

3. cross-platform interface

Cross-platform means far fewer nitpicky details to remember when going from Windows to Mac or vice versa.  The software works the same on all platforms.  

2. tab-completion of filenames, function names and arguments

Okay....this may blow your mind.  When you hit the tab-key, RStudio will try to autocomplete for you.  This can save a lot of time and typos.  For instance, you should NEVER type out the filename "myFile123_FromThatDayICollectedAllThisData.txt", when you could just type "myFile123" plus the tab-key, and Rstudio will complete it for you (assuming that file is in your working directory). 

Even more amazing is using the tab key after typing a function. You probably don't have all the possible arguments to every R function memorized....but Rstudio does.  For example hitting tab from within lm() shows you the possible arguments you can supply to this function, and what they mean (note your cursor must be within the parentheses).

Click to enlarge: auto-completion and function help using the tab key

1. seamless Rmarkdown and knitr integration

For me, this is the most revolutionary part of the Rstudio ecosystem.  Rstudio (with knitr) allows you to seamlessly document what you are doing while you are doing it.  It also provides a streamlined way of saving figures and output. Instead of writing code in a normal text file, you write it in a simple markdown format.  You embed your R code within this markdown file, so your code is mixed in with your comments about it.  With a single click, you can turn this markdown file into an html document that includes any output from your R code (text or figures) right in context with your normal text. The figures are saved in a single folder, and are named in a sensible way.  RMarkdown and knitr in RStudio is a real step forward in documenting analyses.....check back for a later detailed post on how this works. 

Final note: Some of these tools are present in other IDEs for R, but RStudio provides a really excellent full package (and nobody can touch RStudio in terms of #1). Trust will do more data analysis faster and with fewer headaches if you use Rstudio!

No comments:

Post a Comment