TOPICS
1. What is R
3. How to start using R with
Emacs (but also without)
4. Using R
5. Dealing with the
Italian keyboard
6. Housekeeping
7. 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/
It is possible 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/) . This choice
is strongly recommended under Linux, and advised (if you are able to do some
system customizing) under Windows or MacOS. Under Windows or MacOS, the R
software includes a text editor that may be otherwise used.
2. R, Emacs and ESS are installed under Linux and
Windows in the computer labs of the Science Faculty.
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 also ESS under Ubuntu. If not, you can visit 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...)
a) Using Emacs under Windows. Step 1. Start
GNU-Emacs from the Start button; this will open a window (be patient; it may
take a littel while) with written on GnuEmacs and several other things.
To create a new file, you can press the icon of New file (if this does not
work, you can 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. Choose a name something.r
If you already have created a file and wish to re-open
it, you can do the same giving the name of the existing file, or more simply
click on the icon of the file; this (if everythingÕs configured correctly)
should start Emacs opening that file.
b) Using Emacs under Linux. Step 1 Under Linux,
it is more usual first opening a terminal window, and then write emacs something.r
. This starts Emacs and opens or creates the file something.c
c) Using Emacs. Step 2At
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.
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.
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..)
d) Using the text editor included in R (Windows or
MacOS) Start R from the program list. This will open a Command window. Find the
icon or the Menu-option that lets you open a file under a text editor. You will
now have two windows open, the command window and one with a file.
4. Using R.
Under Emacs, your window will be split in two. 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.
Using the included text editor, the concept is the
same: you have one window (the text editor) where you write your commands, and
another window where you see the output of the commands. The only difference is
that the buttons to execute the programsmay be different, but are quite
intuitive.
How to get out from Emacs? 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. Dealing with
the Italian keyboard. Unfortunately, those that designed the Italian
keyboards were not aware that certain keys are essential in programming. While
[ and ] can be seen on the keyboard, and obtained pressing AltGr, obtaining a ~
is more difficult. ~ is a totally essential key in R, and one needs to be able
to produce it. One choice (that I've seen used) is to copy a ~ from somewhere
(on the web?) and then pasting it where appropriate. But there are other
(better?) options:
- Under Linux, ~ is produced using AltGr-“ (accented
i).
- Under Windows, ~ is produced using Alt-126 [keep
pressed the Alt key, while pressing 1, 2 and 6 one after the other].
Unfortunately, this does not work in Emacs, because the Alt key is interpreted
by Emacs. The best possibility is to redefine a key (for instance F2) to make
it ~. I have prepared on my Web page a file named .emacs with the single line
(global-set-key
[f2] "~")
You
should copy that file into your directory Z: (your own disk space accessible
from any computer in the faculty). This is not yet all, because in the system
the environment HOME (where Emacs looks for command files) is not defined. You
should also define Z: as HOME; at http://www.itechtalk.com/thread3595.html
is a guide on how to do that (variable to create HOME ; equivalence Z:)
On
your own computer, you will do more or less the same, except that you will
define HOME (if not already defined) as C:something É
I
must admit that all this needed procedure, under
Windows with an Italian keyboard, is somewhat a deterrent against using
Emacs with R.
6.
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.
7. 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/