Quick links: install R | R code used in class  | Getting started, part 1

R software

R is an open-source statistics software package and programming environment. We will use R for data analysis and to carry out simulations. The information on this page about R is specific to Windows. Users of Linux or MacOS should see the R download page at the Comprehensive R Archive Network (CRAN).

Installing R for Windows

R consists of a "base" distribution and add-on packages that may be downloaded and installed separately. To install the base distribution, download the Setup program (about 20 megabytes) and run it. The setup will ask you to agree to the licence and ask for a location on your computer to install R.

Running R

When R is installed you should see an icon on your desktop. Double click to start. The RGui window will start in full-screen mode (i.e. it will take up your entire computer screen). Within the RGui window is the R Console where you type your commands. One important command is q() to quit R. You can also quit with the Exit option of the File menu.

Installing packages

The easiest way to install packages is directly from the web. To install a package, start R and choose the Packages item from the menu. Choose Install package(s) from CRAN to install from the web (you will see a list of all available packages pop up -- choose the one(s) you want). For those who prefer the command-line, type
> install.packages("packagename")
from the R prompt (the >) to fetch the package named packagename from the "master" R website, or
> options(CRAN="http://stat-db.stat.sfu.ca/CRAN")
> install.packages("packagename")
to fetch packagename from a local R "mirror" site.

To use a package you have installed, use the Packages-->Load package menu item to load the package for use. Alternatively, from the R-prompt type

> library(packagename)
Packages you may find useful are

Examples

Sometimes the best way to learn a new programming environment is by studying examples. You may find some of the code we will use in class helpful for this purpose.

Getting help

If you would like more information about R and using R see the manuals page on CRAN.

There are also many websites written by R users. For example Rtips has a list of tips the author found useful while getting started with R. We have also prepared a Getting Started page with examples drawn from the first homework. You should also feel free to post messages to the class caucus for R help.