Web EndMemo

R Installation on Windows

Download R from here. Select a hosting site, for example, we may select USA -> http://watson.nci.nih.gov/cran_mirror/ (National Cancer Institute, Bethesda, MD). Next select "Download R for Windows". Click into "base", then click "Download R 2.xx.x for Windows". Save the file on your computer, or you may start install by click "Run" button instead.

Click the downloaded file "R-2.xx.x-win.exe" to start installation. You may accept all default setting and click next all the way to finish the R installation. By default, there will be a R shortcut on the desktop after installation. The R can be started by clicking that icon.

The default working directory should be "C:/Users/xxx/Documents/". To check the working directory, type getwd(). There are several methods to change the default working directory. 1. Open a random folder, click "Desktop" icon on the up left to open the desktop directory. Right click the R shortcut icon, select "properties", change the "Start in" directory.
2. Add R to the PATH environment. Right click "My Computer" -> "Properties" -> "Advanced" -> "Environment variables", then append the R to the path. You now can start R from the windows shell.
You may use setwd() to temporarily change the working directory.

R Installation on Linux

Download R from the same website. For example, for Redhat Enterprise Linux 5 (RHL5), Select "Download R for Linux" -> "redhat" -> "el5" -> "x86-64", and download the R-2.xx.x-xx.

Go to the downloaded file folder, type rpm -ivh R-2.xx.

Since R has been maintained in the standard yum repos, you may install R by type yum install R, or yum update R to get a recent version.

open .bashrc file under /root/, append the R bin path (add to .cshrc, if you use c shell):
export PATH=".:$PATH:/app/R-2.xx.x/bin". R can then be initiated from any directory by typing R.

R editors (recommended):
• Notepad++: Windows Only
• gedit: Redhat Linux Only
• RStudio: Powerful IDE, works on Windows, Mac and Linux

Quit R:

If you select "save Workspace image" during quit, all R objects will be written into a file ".RData" in the working directory, and all history command will be recorded into a file ".RHistory" in the working directory. By default, R will load all objects while starting. This may save time if you want to read a large file, but waste you time if you do not need the objects. You can delete the .RData and .Rhistory under the R working directory to delete all R objects and history commands.

Getting Help, for example function plot():

Execute a R command file:
Or under linux shell:
R CMD test.R

>sink("output.txt") #Divert output from console to file
>sink()  #Restores to the console output
>objects() #Display current objects
>ls() #Display current objects
>rm(x) #Remove object x from R work space
>getwd() #Display current work directory
>data() #Display all built in datasets
>install.packages("mmass")  #Install package mmass
>installed.packages()  #Display all installed packages
>ls("package:base")  #List all functions of R Base

You may use the upward and downward arrow to recall and reexecute previous commands.