Notes on R
For detailed information on R, the Universe, and Everything, see the R html documentation.
A useful listing of most of the "core" R functions, which are
organized into various "packages" can be found in the following
places:
As a brief intro, aimed basically at those who have done a bit
of S-ing around, I offer the following:
- R now runs both on all three
of gelfand, tanner, and erdos, on our system. It is
also available on the Novell network.
- You can get a copy of R for your own machine, for Unix/Linux,
MacOS, or Windoze, from
this URL.
(Look under "Download".)
- To get started on the Unix systems, simply type   R
- To suppress the start-up message, add a ``-q flag'':    
R -q .
- To get R going on Novell click on the R icon in the
``Novell Delivered Applications''. This will (just) create a similar
icon on the local ``workspace''. Click on the latter to start R.
(This latter icon will hang around until some overt action is taken
to make it go away. So you will only have to go to ``Novell
Delivered Applications'' intermittently.)
- To see a demonstration of the graphics capabilities of R, type
demo(graphics). (If you get bored and want to stop
before all the examples have been displayed, type CTRL-C
instead of RETURN at the prompt.) (At least, this
works under Unix; I'm not sure about the Novell version.
- To see some examples of linear and generalized linear modelling
(taken from Annette Dobson's little book) type demo(lm.glm)
. (A whole lot of output, which is not paged, flies by. To catch
this output so as to be able to examine it at leisure, type (e.g.)
sink("demo.out"), then demo(lm.glm), then press
RETURN once, then type sink() . This will
create a file ``demo.out'' containing the output of the demo, which
you can print or examine with a text editor, or with ``more''.
- There is online help; e.g. help(sink) or ?sink
. The function help.search("topic") is useful.
- If you want hard copy of some documentation, type, e.g.
> help(plotmath,offline=TRUE)
which will create a file plotmath.ps, which you can then print. (Or
it may send the output directly to the printer if you've made a local
adjustment to the flags for dvips.)
- It may be useful to note a (subtle?) difference between R
and S/Splus which is that in the case of R the ``workspace'' or basic
data base is saved as a (binary) file, not
as a directory. This file is named ``.RData'' and lives in the
current working directory. (In S/Splus the workspace is a
sub- directory of the current working directory,
named ``.Data''.)
The file .RData is not created or modified unless/until you quit from
your R session and choose to save the workspace. (See below for a
bit more on this.)
A result of this is that you automatically get a different saved
workspace/data base in each directory in which you invoke R.
[Contrast with S/Splus: Here the data base (.Data) in your home directory is used unless you explicitly
create, using the Unix command mkdir, a directory .Data in the
current working directory.]
- Command-line editing in R is there automatically; just use the
arrow and delete and backspace keys.
Or, if you are civilized (like me), and want vi syntax in
your command-line editing, press the escape key and then press the
control key and ``j'' simultaneously, after which pressing
the escape key puts you into vi editing mode. You can get
vi editing mode automagically by creating a file called
.inputrc
in your home directory, and in that file place the line
set editing-mode vi
(Of course all this doesn't work on Novell, but.)
- Command-line editing allows you to find, edit, and re-issue
commands from previous R sessions, which
are saved as the ``history'' of a session in a file called .Rhistory
(in the current working directory). A catch: When you quit from R,
you are prompted for whether you wish to save the work space (like
APL; different from S/Splus). If you don't save the workspace then
your ``history'' is not saved either -- unless you (somehow,
explicitly) issue the command
savehistory()
- So that I don't have to remember to do this, I've placed
in my file
~rolf/.Rprofile
the lines
if(!exists(".Last")) {
.Last <- function() {if(interactive()) savehistory()}
}
so that my history gets saved whenever I invoke and then leave R,
whether I save the workspace or not. (The `` if interactive() ''
jazz avoids a screw-up when one is doing something like
R --save -q < infile >& outfile
(where ``infile'' is a file of R commands to be executed and ``outfile''
catches any messages or displays that would be printed on the screen
if you were running interactively).
- There is no ``point-and-click'' button to print a screen
plot (as there is in Splus), but printing of the screen (x11) plot
can be done by means of
dev.print()
(see the help). Likewise dev.copy() is useful.
- The default orientation for PostScript files of graphics is
landscape; this can be over-ridden by giving the argument
horiz=F to the postscript() device driver, or to
the ps.options() function. Personally I want portrait
orientation to be the default, so I have put in my .Rprofile file
the line
ps.options(horiz=F)