Starting R
R runs on the Cent-OS Department of Astronomy computers. To
start the program, type
R
at the command
prompt. R will start in the window. To get help on, for
instance, the plot command, type
?plot
You can then scroll up and down in the window, perhaps copying one of
the examples at the bottom, and then quit by typing
q
You can search for a command topic with
help.search("plot")
to get all the help pages involving the word plot.
If you have set the environment variable for the browser (see below), you can
type
help.start()
for a nice HTML browser that links to command searches and
documentation including "An Introduction to R."
Apropos plotting, see
- plot for
the basic routine
- par for
setting plot parameters
- lines and points for
overplotting,
- curve for
plotting functions
- barplot for
bar plots
- hist for making
histograms
- max, min, and range to
get the max and min.
To
quit R, type
q()
It will ask if you want to save the environment. Answering yes
saves the command history (see history)
and whatever variables are in the working memory (see ls).
You can delete the variables in memory with rm(list=ls())
if you want to save the history but not the stuff in memory.
Quick notes on installing and using R packages
R comes with a pretty comprehensive set of functions in its base
"packages," but there are over 1500 additional packages contributed by
users. Some provide special functions, others code for specific
applications, some contain the routines for books. FITSio is a
package for reading and writing FITS files, for instance.
Downloading and installing the packages is easy.
Set up a local
user library directory and environment variables
mkdir Rlibs
Then, either add the
following to your .csh file or type at the command line (for just the
session)
setenv
R_LIBS_USER ~/Rlibs
setenv
R_BROWSER /local/bin/firefox
setenv R_PAPERSIZE 'letter'
Installing a package from a CRAN repository
Start R, then
install.packages("FITSio")
(you will probably need to wait a little for the
repository drop-down to appear, then select repository)
Now that the package is installed, you load it
with the command
library('FITSio')
To get information on the package and its
functions, type
?FITSio
at the R command line.
There is an "index" key at the bottom of the page to
show you the different commands, or for a specific command, type
?readFITS
To remove a package
remove.packages('mypkg'
[, lib='~/Rlibs'])
Questions or comments? Please contact Andrew Harris.