Getting started with R

For the past three years I have been chipping away at R — going up what has been a very steep learning curve. For the most part, it has been a fun (if nerdy) pass-time — characterised more by satisfaction than frustration. The aim of this post is to help new users get onto a track that will ultimately be fruitful.

The difference between R and excel is somewhat like the difference between a terminal (or shell) operating system and a GUI (or Windows) operating system. For like the terminal, R is not ‘user friendly’ AND in the right hands it is extremely powerful.

So my first bit of advice is to get comfortable in the shell. Real power-use of a computer (regardless of if you are using R or not) requires some heavy lifting in a ‘terminal session’ — being comfortable in this environment is a necessary condition for getting really useful in R.

If you need to brush up on the shell, do the CLI course at Zed Shaw’s awesome ‘Learn Code the Hard Way’ site.

Next, pick a text editor: my advice is to choose one of vim or emacs and to just stick with it.

Using R is really about cutting code. When I’m ‘using R’, I’m not really doing much in the R GUI — I’m tinkering away inside Vim, with an R session open. I write a little bit of code in vim, test it in the interactive R session, and then when satisfied save that chunk some place and repeat on the next part of my task. At the end of a few hours I have a working R script.

There are two very good reasons that you should pick one of emacs or Vim:

1/ both have vibrant communities that will help you when you get stuck (and you will get stuck).

2/ both are robust programs with robust communities. Sure — everything dies at some point, however these two communities seem very robust. You are going to spend a lot of time with your editor, and you don’t want to be stranded with 2000 hours of experience with an abandoned editor. Both editors are freakishly awesome, and do much the same thing (which is why the conflict between the two groups are so heated).

I clicked with Vim, however if you only want to use R, you’re probably going to find things a bit easier if you use emacs.

If you use Vim, you should get the vim-R-plugin (here’s the git); emacs users use all use ESS.

If all this sounds too hard (and it is hard; Zed Shaw, for example, recommends you steer clear of vim and emacs at first), you can get most of the way there with the excellent Rstudio.

I know, this seems a long way away from R, but it’s actually right on case.

Why use R? I can tell you why you should — because if you use R you will create robust, repeatable, reliable work. To get there, you are going to have to become something of a programmer.

For really using R is writing and testing code. To get good at it, you are going to have to write and test code for many hours.

So you if you are going to have spend many hours being like a programmer, you should get a text editor professional programmers use. It’s hard at first (particularly vim), but you can look forward to your first nerdy first pumps when you learn how to customise your editor to make life a little LOT easier.

Advertisements
This entry was posted in R. Bookmark the permalink.

3 Responses to Getting started with R

  1. Mark Graph says:

    Ricardo, I am a great fan of R. I find the consistency and reliability you can achieve to be much better than excel. You have a different workflow to me, so some ideas for me to check out. (I work on an Apple MacBook Pro, and like you I do a lot in the terminal window and with shell batch files).

    I put together some cheat sheets on R (as part of my learning approach). They can be found here: https://docs.google.com/folder/d/0ByIrJAE4KMTtcVBmdm1BOEZoeEk/edit?pli=1

  2. Pingback: Getting started with R — part 2 | ricardian ambivalence

please comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s