R software
R is an open-source language and environment for statistical computing.
You can think of it as a highly customizable statistics package.
We will use R for data analysis and simulations.
The information on this page about getting started with 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 28.5 megabytes) and run it. The
setup will ask you to agree to the licence and ask as series of
questions, such as a location on
your computer to install R. Accepting all the default answers to
these questions is a good idea, at least for the first time
you install R on your computer.
Starting R
The setup program will create an R icon on your Desktop (assuming you
didn't specifically tell the setup program not to). Double-click
the icon to start. R will start in "full-screen" mode and will occupy
your entire computer screen. Most people will want to toggle full-screen
mode off (with the usual Windows method of clicking
the middle of three buttons in the top-right of the
window). Users can type commands into the R Console window. For example,
try the following (the > is the R command prompt -- don't
type this in yourself):
> plot(1:100,rnorm(100))
> example(plot)
The first command will start a graphics window. We'll learn more about
the rnorm command in class. The second command runs
a few examples from the plot help file (NB: the examples
function prompts you to change the graphics window page with a message
Waiting to confirm page change ... which you can do
by clicking anywhere on the graphics window).
You can access the help page with help(plot), which starts
the help browser. In general, help(func) gives you
help on function func.
To quit R type q() at the command-line, or
select Exit from the File menu. You will be prompted to either
save or discard your work. More on this later, but for now you can
safely say No.
Installing packages
To install packages you have (at least)
two options. Both assume you are already running R and that
your computer is connected to the internet.
The first option is through the Packages item of the main
menu. Choosing "Install package(s) from CRAN" will
pop up a list of websites that host R software. Choose
the "Canada (BC)" and click "OK" to download from an SFU mirror
of the R project. You will then see a list of packages pop up --
choose the one(s)
you want.
Alternatively, you can install packages from the command-line. For
example, to install the Rcmdr package (read "R Commander"):
> install.packages("Rcmdr",dependencies=TRUE)
where dependencies=TRUE ensures that any packages
that Rcmdr depends on are also installed.
To use a package you have installed, either use
the Packages-->Load package menu item or type
library(pkgname), where pkgname is the
name of the package.
Getting help
If you would
like more information about R and using R see the
manuals
page on CRAN.