mines
Table of Contents
1 Configure R user library and install packages
The Mines Paristech unix machines have access to R-2.7.1 at /usr/bin/R
We will be using R packages that we will download from CRAN into a personal library that we will create in ~/R/library
Further complicating things is the fact that the Mines computers need to use a proxy to access the web: http://www-proxy.ensmp.fr:8080
However, this should be no problem if you copy and paste the following R code into your ~/.Rprofile
ldir <- "~/R/library" if(!file.exists(ldir)){ dir.create(ldir,recursive=TRUE) } .libPaths(c(ldir,.libPaths())) options(browser="firefox") options(repos=c("http://cran.univ-lyon1.fr/", "http://cran.r-project.org")) Sys.setenv(http_proxy="http://www-proxy.ensmp.fr:8080")
Then open a terminal, type R, and copy/paste the following lines of code to install the required packages
install.packages("ROCR") source("http://bioconductor.org/biocLite.R") biocLite("ALL")
2 Using R
2.1 Basic usage
The basic idea is that R is a command line interpreter. Write code in a text editor like medit, which is installed by default on the Mines computers and has basic support for syntax highlighting of R code. When you want to execute the R code, you can either copy/paste code into R running in a terminal, or in R do
source("my.script.R")
which will execute all the code in the file my.script.R
To get help, type a ? and then the function name. For example, ?plot shows you the help page for the plot function. Or type help.start() to get a HTML help interface.
At the R command line, you can use TAB completion for variables, functions, and arguments. For example if you forgot the name for reading data, you can just type "read", then TAB twice will give you a list of possible functions. After typing "read.t" TAB will fill in and give you "read.table". Add a parenthesis to make it "read.table(" and hitting TAB twice will show you a list of valid keyword arguments to the read.table function.
Some useful keyboard shortcuts. C-a means hold control and type a. M-f means hold Alt and type f.
shortcut | function |
---|---|
C-p or up arrow | recall previous command |
C-n or down arrow | recall next command |
C-a | go to beginning of line |
C-e | go to end of line |
M-f | go forward 1 word |
M-b | go backward 1 word |
M-d | delete word in front |
C-delete | delete word in back |
C-k | delete until end of line |
C-y | paste deleted word(s) |
2.2 Advanced usage
Emacs Speaks Statistics (ESS) provides a better development environment for R programming. http://ess.r-project.org/index.php?Section=download
To use it on the Mines Paristech unix machines, execute the following code in a terminal to download and setup ESS:
cd ~/R wget http://ess.r-project.org/downloads/ess/ess-5.13.tgz tar xf ess-5.13.tgz cat >> .emacs <<EOF (add-to-list 'load-path "~/R/ess-5.13/lisp") (load "ess-site") (setq ess-eval-visibly-p nil) (setq ess-ask-for-ess-directory nil) (require 'ess-eldoc) (show-paren-mode 1) EOF wget http://cbio.ensmp.fr/~jvert/svn/tutorials/practical/svmbasic/svmbasic.R wget http://cbio.ensmp.fr/~jvert/svn/tutorials/practical/svmbasic/general.R
Then you can do open up a new R code file in Emacs from the command line using "emacs svmbasic.R &"
When writing R code from within Emacs you get context-sensitive help. For example, after typing "read.table(" Emacs will display the list of arguments for the read.table function. Additionally, you can use the following keyboard commands to evaluate R code:
Shortcut | Function |
---|---|
C-c C-n | Send 1 line of R code |
C-c SPACE | Mark current position |
C-c C-n | Send code between mark and point |
C-c C-l | Send entire buffer |
C-c TAB or C-c C-i | Complete |
Furthermore the R from within Emacs buffer has similar shortcuts to R in the terminal, but with the following exceptions:
Shortcut | Function |
---|---|
M-p | Recall previous command |
M-n | Recall next command |
Org version 7.5 with Emacs version 22
Validate XHTML 1.0