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.
R consists of a "base" distribution and add-on packages that may
be downloaded and installed separately. Instuctions
for installing base-R on Windows and Mac are given below.
Users of Linux can probably figure it out themselves and
should see the
Linux downloads page.
Installing R for Windows
Download the Setup program
(about 38 megabytes) and run it. The
setup will ask you to agree to the licence and ask a 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.
You should find an R icon on your desktop that you can use to launch R.
You may also have R on your Windows Start menu.
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.
Installing R for Mac OS X
(NB: I'm not a Mac user and have only tried this installation
once on a borrowed MacBook.)
-
Before downloading and installing R, you will need to install a software
library called Tcl/Tk. You can find this on the
Mac OS X tools page.
At the time of writing, the current version is 8.5.5:
tcltk-8.5.5-x11.dmg .
Download this to your computer and install it.
On the MacBook I tested with, the library auto-installed after downloading.
If yours doesn't you might try the installation instructions at
http://www.ofzenandcomputing.com/zanswers/779/
- Download R, currently at version 2.13.1:
R-2.13.1.pkg
and install it. This is an installer that should end up in your "Downloads"
folder. Install by double-clicking the icon and following the instructions.
Accepting all the default answers to
these questions is a good idea, at least for the first time
you install R on your computer.
You should find an R icon in your Applications folder
that you can use to launch R.
You may have 2 versions of R installed, one called just R and one called
R64. You can use either. I used R64.
Working in R
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.
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
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.
(Complete Rcmdr installation instructions from the package's author
are available
here.)
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.