TOPICS

 

1. What is R

2. How to install R and ESS

3. How to start using R with Emacs

4. Using R

5. Housekeeping

6. About the additional packages

 

______________________________________________________________________ **********************************************************************

 

1. R is a free environment for statistical computing and graphics, originated as a dialect of the S language. It is available under Linux and Windows. It may be used directly from a shell and the operating system, and more conveniently with a windowing system. Plenty of documentation is provided as on line help and at the project site http://www.r-project.org/

 

We advise to use R from within Emacs (a text editor, see http://www.gnu.org/software/emacs/ ) connected to R through the package ESS (see http://ess.r-project.org/)

 

2. R, Emacs and ESS are installed under Linux and Windows in the computer labs of the Science Faculty (despite some temporary problems, due to the new installations). You may want to install them in your home computer.

 

You can download R from http://cran.fhcrc.org/ (if, for instance, you use Windows, you click on Windows, then on base, finally on Download R ).

 

A version of Emacs (for Windows or MacOS) already incorporating the package ESS can be found at http://vgoulet.act.ulaval.ca/en/ressources/emacs/ .

 

Once R and Emacs are downloaded. you should simply click on them to install them (follow instructions). It is advisable to install R first, then Emacs.

 

If you use Linux, Emacs is generally already installed and you can download ESS from  http://ess.r-project.org/

 

3.  Starting R from an editor like Emacs allows to take advantage of interaction with the graphics and help resources. Here we describe how to start using Emacs under Windows , taking advantage as much as possible of the Menus and icons on the menus (a lot of instructions are available under Emacs with suitable Ctrl sequences...)

 

Start GNU-Emacs from the Start button; this will open a window with written on GnuEmacs and several other things.

To create a new file, you should press CTRL-X CTRL-F (=Open File); this opens a space on the bottom bar of the window in which you can write a name of a file. If you write a name to which does not correspond the name of an existing file, ths creates the file: choose a name something.r

[You could try to press the link in Open file... or the Menu icon Open File ; under Windows, in the implementation I tried, this forces you to open an already existing file, and does not let you give a new name]

 

Under Linux, it is more usual opening a terminal window, and then write emacs something.r . This starts Emacs and opens or creates the file something.c

 

At this point, the Menu bar should have changed with some new buttons (one has written R on it; others to the right have an arrow and lines below it) on the bar. This is because Emacs has recognized (through the extension .r or .R) the file as a file of R script, and gets ready to interpret it. Now one has to start R and to split the window in two parts.

Under Windows. you can do this just in one stroke: press the button with an arrow and a single line below it (=EvalLine & Step). This starts R: you will be asked which is the data directory: you can choose any one, but it is better to have first set up a folder in which to work in R; then the process goes on: the window gets split in two and in the lower part you should see something similar to

 

R : Copyright 2004, The R Foundation for Statistical Computing Version 2.0.1  (2004-11-15), ISBN 3-900051-07-0

 

R is free software and comes with ABSOLUTELY NO WARRANTY.

 

You can now write R commands in the upper window (where the cursor presumably should be), and the output of the command will be seen in the lower window.

 

Under Linux, I believe this does not work. You can first split the window in two (CTRL-X 2), then, after having moved the cursor to the lower part of the window, start R (pressing the R icon or ESC-X R): probably you will be asked to confirm that you want to start R, and you should get in the same window configuration as described above [if you haven't moved the cursor, you should see above the window with R outputs, and below the one for writing commands, but it makes no difference]. Alternatively, you can start R (pressing the R icon or ESC-X R), confirm that you want to start R and you will get the window (not split) with written

R : Copyright 2004, The R Foundation for Statistical Computing Version 2.0.1  (2004-11-15), ISBN 3-900051-07-0

 

R is free software and comes with ABSOLUTELY NO WARRANTY.

You can now change buffer (from the Menu), going back to the file something.r and, as soon as an R command is given, the window should split and you should see commands in the upper parts and output in the lower part.

 

Depending on the exact configuration, the exact command sequence may be slightly different, but you should be able to learn and remember the correct one (it is just a couple of commands..)

 

4. Using R. Now in the upper window you can write R commands and execute them one at a time, pressing (with the cursor on that line) the button Eval Line & Step (the one with an arrow and  a single line below it) [or, alternaiively with Ctrl-C Ctrl-N] . You can also select a region and execute all commands in that region pressing the button Eval Region (the one with an arrow and several lines below it). The ourput of the command will be seen in the lower window.

Remember that commands are executed only if the appropriate button is pressed; the fact that the command is written in the window does not mean that it has been executed.

 

How to get out? Doing this in an orderly way, you should execute the command q() (=Quit); this exits from R, and saves an .Rdata file that could be re-used the following time. Then we can exit form Emacs, either through the menu, or pressing Ctrl-X Ctrl-C, or even (under Windows) closing the window; we will asked to save changes to the file, if any.

You can also exits from Emacs, without having first exited from R. You will be warned that there active processes, and asked whether you wish to kill them; saying yes, R is stopped without saving the .Rdata file. Since we never re-use them, one can use this shortcut, saving one command, although probably serious R users would not recommend it.

 

5. Housekeeping: R can be started in any directory. However the objects produced in a session will be saved for next sessions into a .Rdata file, thus it is a good idea to prepare a working directory for each project. Example, create a DAE directory and start from there. Do separate data and scripts, as appropriate. 

 

 6. About the additional packages

 

A list of installed packages, with dependencies, is available as installed.packages()

 

Users cannot install additional packages on the laboratory computers. Updates or addition will be centrally maintained.

 

On your home computer, you may wish to add new packages. You can find the list of available packages and instructions on download at the FAQ page of http://cran.r-project.org/