R
R is a freeware statistical analysis program. First released as a
"toy" package in 1995, it has become a leading stat package because of
the improvements which are continually being contributed by
statisticians world-wide.
For home use, download it from Main R Site.
For a tutorial, start R, (just type "R" on our Sun machines, or click
the R icon in Windows) then type "help.start()" (or use the Help menu in Windows) and when
the browser window opens, choose "Introduction to R". A PDF version of the introduction is here. The sample session is a
good place to start if you're in a hurry to see what R can do. Or for
up-to-date information and downloads, see the
Main R Site.
R is a project under development in alpha release 2.6.1 (October,
2007). The original authors' (Ross Ihaka and Robert Gentlemen)
purpose was to create an S-like language with the ability to
handle loops better than S or Splus. Interest in R has
skyrocketed in the last few years, and now a large group of
people are contributing to the project.
It runs on our Sun workstations, just type R, but you need
/opt/local/bin in your path.
R and SPLUS are both versions of the S computing language. The reference
manual for R is easily accessed with the help.start()
command. R has some functions not available in SPLUS, for
instance, dataentry() command opens a spreadsheet for
data input.
Distribution and resources:
To get your own copy of R, documentation, and/or addons, or to find out
about mailing lists, visit the Main R Site hosted by the
stat department at University of Wisconsin, Madison. They even put out
a newsletter now:
R Newsletter.
Packages
R stores the current session (objects like data and functions) in
memory. To keep memory usage small, it relies on packages which are
objects which can be loaded when needed. The base package is always
loaded, but other packages are only loaded when called, for example\
library(lattice) loads up a library of fancy plotting
routines.
If you have a web connection and R for windows, packages can be
downloaded with a few clicks under the packages menu, and you can
easily update any or all of the packages you have installed. The
windows distribution comes with 8 packages, but there are almost
200 packages available (well, not all have a windows version).
R within Emacs on UNIX machines
I strongly recommend running R from within the Emacs editor using ESS: Emacs Speaks Statistics, because
it allows you to quickly revise and resubmit code. I use two windows
running under one emacs session:
- one window for the R session Start emacs as in:
> emacs &
Start R by typing Meta^X R (Meta^X means hold down the diamond
key while you press x, then shift-R).
When it asks which directory to start in just return to run in the
current directory or you can specify any subdirectory.
- another containing the code I want to run and the output I
want to save. Click on these options to open a new window:
File (Menu)
New Frame
In the new window,
File (Menu)
Open File
and type in a file name. It does not need to already exist.
If the above commands don't work, you need to copy a specially tailored
.emacs file to your root directory. One way to get one that works is
to copy mine with the command:
gauss> cp ~jimrc/.emacs .emacs
(close and restart emacs if it's already going).
For more details on running within
emacs see Emacs Speaks Statistics, ESS.
Help:
Within R, type:
help.start()
and choose the introduction or the FAQ. The intro includes a sample
session which you should work through.
You can get help on any function by typing help(function.name).
However, it's hard to know what function toask for when just
starting. For a partial list of useful functions see this
reference card.
The command help.search("topic") searches the installed
packages, and
RSiteSearch("topic") searches the CRAN web site for functions related to some
topic.
Quitting:
To exit R, type q() . It will ask if you want to save your
session. If you type "y" (without the quotes), then the variables
you've created in one session will be available for the next
session. If you reply "n", then your recent data will be dumped.
My advice is to keep all code so that you can re-run any analysis
later. Then you do not need to save the session image.
If you have
some functions which you use often, then you might want to clean up
the workspace, input the functions, and save the image like this:
> objects() ## lists the data & functions in memory
> rm(temp1, olddata, etc) ## remove old stuff
> source("file_of_functions.R") ## read in the functions
> save.image() ## save the stuff in memory for future sessions
Info on unix and emacs.
Other Stat package demos for unix packages:
Back to MSU Math Department Home Page
Author: Jim Robison-Cox
Last Updated: Wednesday, 09-Jan-2008 14:28:11 MST