R Frequently Asked Questions
What version of R do I run?
You can find this information by running
R.version.string at the R prompt:
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:
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:
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
Method 2: Install from source. At the Linux prompt download the R package my_package.tar.gz and use
R CMD INSTALL command:
Note: Regardless 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:
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.
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.
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:
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:
How can I run another R version installed on katana?
You can list and run non-default versions of R available on katana, running the following commands at the Linux prompt:
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:
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:
4. Run the following code in the new version of R: