What version of R do I run?
You can find this information by running
R.version.string at the R prompt:
# get version of R > R.version.string  R version 2.13.2 (2011-09-30)
What R packages do I already have?
To get a list of installed packages, execute
library() at the R prompt. R will first list all the packages installed in your local R directory and then it will list all of the packages installed globally on your system:
# list all R packages installed > library() Packages in library '/usr1/scv/username/R/x86_64-unknown-linux-gnu-library/2.13': combinat combinatorics utilities proftools Output Processing Tools for R rgl 3D visualization device system (OpenGL) Packages in library '/usr/local/IT/R-2.13.2/lib64/R/library': KernSmooth Functions for kernel smoothing for Wand & Jones (1995) MASS Support Functions and Datasets for Venables and Ripley's MASS
How can I find additional information about R packages I have?
If you would like to get additional information about the installed packages you can access it using
installed.packages() at the R prompt. A more concise output can be obtained running
installed.packages()[ ,c(1,3,4)]. This will include the name of the package, its version and “priority” information:
# Obtain information about installed R packages > installed.packages()[ ,c(1,3,4)] Package Version Priority combinat "combinat" "0.0-8" NA rgl "rgl" "0.92.879" NA MASS "MASS" "7.3-14" "recommended" Matrix "Matrix" "0.9996875-3" "recommended" base "base" "2.13.2" "base" ...
If priority is
“base”, the package is already loaded into your workspace, so all its functions are available upon opening R.
If priority is
“recommended”, then the package was installed with base R.
If priority is
“NA”, then the package is an optional package. Both “recommended” and “NA” packages have to be loaded using
library() command before using them.
How do I install a new package?
Method 1: Install from CRAN directly. A package can be installed using
install.packages("package name") at the R prompt. You can also provide a path name to install R package at a specific location:
install.packages("package name", lib="/my/own/R-packages/"). If the
lib="" option is omitted it defaults to the first directory in
# Install rgl package > install.packages("rgl") Installing package(s) into '/usr1/scv/username/R/x86_64-unknown-linux-gnu-library/2.13' (as 'lib' is unspecified) --- Please select a CRAN mirror for use in this session --- Loading Tcl/Tk interface ... done ...
Method 2: Install from source. At the Linux prompt download the R package my_package.tar.gz and use
R CMD INSTALL command:
# Download rgl package scc1% wget http://cran.r-project.org/src/contrib/rgl_0.92.894.tar.gz --2012-11-16 09:08:34-- http://cran.r-project.org/src/contrib/rgl_0.92.894.tar.gz Resolving cran.r-project.org... 220.127.116.11 Connecting to cran.r-project.org|18.104.22.168|:80... connected. ... # Install rgl package scc1% R CMD INSTALL rgl_0.92.894.tar.gz * installing to library '/usr1/scv/koleinik/R/x86_64-unknown-linux-gnu-library/2.13' * installing *source* package 'rgl' ... checking for gcc... gcc -std=gnu99 ... ** building package indices ... ** testing if installed package can be loaded * DONE (rgl)
Note: Regardless of the method you used to install the package, it has to be loaded into the workspace before you can actually use it. To load it, type
library(my_package) at the R prompt.
How can I remove a package?
A package can be removed using
remove.packages("package name") at the R prompt:
# Remove rgl package > remove.packages("rgl") Removing package(s) from '/usr1/scv/koleinik/R/x86_64-unknown-linux-gnu-library/2.13' (as 'lib' is unspecified)
How can I check if there are updates for the installed packages?
To check for updates run
old.packages() at the R prompt. You will be asked to specify CRAN mirror. Then R will list all the projects that have a newer version.
# Check for updates > old.packages() --- Please select a CRAN mirror for use in this session --- Loading Tcl/Tk interface ... done ...
How can I update a package?
To install a newer version of a package run
update.packages() at the R prompt. R will list all the packages that have newer versions and will offer to download and install the updates.
# Update all outdated packages > update.packages() ... # Update rgl package only > update.packages( oldPkgs="rgl" ) --- Please select a CRAN mirror for use in this session --- Loading Tcl/Tk interface ... done ...
Where are my R packages installed?
You can view the list of the packages along with their paths running
path.package() at the R prompt:
# Where are my R packages installed > path.package()  "/usr/local/IT/R-2.13.2/lib64/R/library/stats"  "/usr/local/IT/R-2.13.2/lib64/R/library/graphics"  "/usr/local/IT/R-2.13.2/lib64/R/library/grDevices"
What is the default path R uses to install new packages?
You can view the default path R is using to install new packages running
.libPaths() at the R prompt:
# Get the default R paths > .libPaths()  "/usr1/scv/username/R/x86_64-unknown-linux-gnu-library/2.13"  "/usr/local/IT/R-2.13.2/lib64/R/library"
How can I run another R version installed on the SCC?
You can list and run non-default versions of R available on scc1.bu.edu, running the following commands at the Linux prompt:
# List all R versions installed on scc1 scc1% ls -l /usr/local/IT/R* /usr/local/IT/R-2.10.1: total 44 lrwxrwxrwx 1 root root 11 May 17 2010 R -> ../R-2.10.1/ -rw-r--r-- 1 root root 1938 May 17 2010 README drwxr-xr-x 2 root root 4096 May 17 2010 bin/ ... # Run a non-default R version scc1% /usr/local/IT/R-2.12.2/bin/R
How can I install another version of R?
You can install another R version locally in your home directory.
First, create a local directory where you plan to install R. Find the mirror site from which you would like to download R. In the example below we use my_R as a name of the directory used for the R installation. We will be installing version 2.15.2.
Execute the following commands at the Linux prompt:
# Set home directory as a current directory scc1% cd # Create a directory where you plan to install R scc1% mkdir my_R # go into newly created directory scc1% cd my_R # download version 2.15.2 from a mirror site scc1% wget http://lib.stat.cmu.edu/R/CRAN/src/base/R-2/R-2.15.2.tar.gz # uncompress the source code scc1% tar -zxvf R-2.15.2.tar.gz # change into R directory scc1% cd R-2.15.2 # execute configure script scc1% ./configure # build R scc1% make # Run locally installed (non-default) version of R scc1% ~/my_R/R-2.15.2/bin/R
Note that if you have installed packages of your own, the steps below will be necessary to do regardless of whether we upgraded the default version of R or you installed your own new version.
Below is a simple process for installing the updated versions of all of your packages into a new version of R.
2. Run the following code in the old version of R:
3. Run the new version of R:
> packages <- installed.packages()[,"Package"] > save(packages, file="Rpackages")
4. Run the following code in the new version of R:
> load("Rpackages") > for (p in setdiff(packages, installed.packages()[,"Package"])) + install.packages(p)