R: Getting started with R

From Wiki1

Jump to: navigation, search

Main page on R

Don't try to do too much in one session. You might like to just install R and then come back and do further steps such as going through the Venables and Ripley tutorial and installing libraries. Finally you will want to use project directories in which you keep data, scripts and other files pertaining to a particular project.

For a quick start, focus on the items that are marked QUICK START:.


Installing R

Windows, Mac or Linux

QUICK START: To install R, you can go to the CRAN (Comprehensive R Archive Network website) and follow the instructions.

You should consider installing RStudio, a recently released IDE (Integrated Development Environment) for using R that has gained rapid popularity.

You will eventually need to install additional packages which you can do easily whenever your computer is connected to the internet.

Further information

You can get more information on installing R and RStudio at John Fox's website.

Starting to learn R: Tutorials on the Web

Start by working through sample scripts. This is probably the best way to start exploring and enjoying R without getting overwhelmed by long explanations.

After working though sample scripts, you can explore other tutorials:

  1. A list of tutorials recently (January 2012) recommended on the LinkedIn blog The R Project for Statistical Computing:
  2. An annotated list elsewhere on this wiki: R: R tutorials and courses.
  3. An extensive list of on-line books and tutorials is available from the CRAN site.
  4. Chris Green at the University of Washington has an excellent very accessible on-line book: Christopher Green: R Primer
  5. An introductory sample session: http://cran.r-project.org/doc/manuals/R-intro.html#A-sample-session
  6. The very basics from a tutorial at the University of Waterloo.
  7. The first chapter of Venables and Ripley adapted to R VR4: Chapter 1 summary. This is more of an introductory session than a tutorial. It gives a good overview of the potential in using R as well as introducing a number of interesting statistical ideas.
  8. The tutorial that comes with R[1] is extensive but gradually working through it might be the best way to become proficient.
  9. R tutorial at UCLA This is good but takes you through some things you won't really need.
  10. The start of a local tutorial (please contribute)
  11. If you are already familiar with SAS or SPSS you should have a look at Rob Munchen (2007) R for SAS and SPSS Users

Other interesting tutorials on the web

If you find other good tutorials, please add links, preferably with short comments, here

Short introduction to the basic features of R. A good point to start.
Introduction to R with a lot of statistical examples
  • An Introduction to R: Software for Statistical Modelling & Computing 3 by Petra Kuhnert and Bill Venables:
Extensive non-technical coverage of R, 364 pages
Reference introductory text for using R.

Script Editors

The built-in editor lacks some desirable features. For example, under Windows, it does not show matching parentheses. You will probably want to get a separate editor.

Recently released RStudio, which is free, provides an integrated environment including a script editor that will probably displace previously available editors.

RStudio has probably superseded previous R editors but for historical completeness one can metion a number of other possibilities, some of which are free. Emacs is very powerful but difficult to learn, Tinn-R (see below) under Windows is easier to install and use but suffers from less than perfect reliability. WinEdt is not expensive (Academic: US$40) and is considered a very good editor with an interface, R-WinEdt designed for R.

Keeping your work

Probably, the ideal way (as of the fall of 2013) to keep output and to perform analyses in a way that is reproducible is to use R Markdown in RStudio.

A more primitive but simple way to keep output and selected graphs so they can eventually become part of a report is to copy and paste output and graphs into a Word file. Graphs can be copied and pasted as 'Windows metafiles' without loss of resolution. Text in the R output window should be pasted with a 'fixed width font' such as Courier New.

Using and installing packages

Many packages come with R. To use them in an R session, you need to load the package. For example to load the MASS package which contains functions and datasets that accompany Venables and Ripley, Modern Applied Statistics with S, you use the command:

> library(MASS)

To get an overview of what's available in MASS, you use:

> library(help=MASS)

Installing additional packages

Some packages are not automatically installed when you install R but they need to be downloaded and installed individually. An important example is the 'car' package that accompanies Fox, Applied Regression. You install it with the R command:

> install.packages("car")

After installing it you load it the same way as a pre-installed package, i.e.

> library(car)

To get information about the package, use:

> library(help = car)

On your own computer, the package needs to be installed only once. On a lab computer you may need to reinstall in each new session.

At this stage, have a look at R basics on the UCLA ATS web site.

Setting up project directories

RStudio provides facilities for managing project directories. If you are working only with R you can organize your work in project directories as follows:

  • Create a directory for your project.
  • Copy a workspace (a .Rdata file) to the directory
  • You can then start R by clicking on the .Rdata file's icon
  • All directory references in the R session will be relative to the project directory. For example, you can read a file 'data.csv' in the directory with
> data <- read.csv('data.csv')

R lessons


Generate links to a set of lessons people can use to learn R. Each lesson should take approximately 1 hour and contain exercises.

R Tip sheets

Exploring more deeply

Exploring much more deeply

This is not up to date. Please help

  • R Portal at UCLA[4]

Courses in specialized areas



Introductions to R

Materials from John Fox

Materials from John Fox

Use stuff from here: Getting Started page on the old math wiki

Personal tools