R packages

Part of this post is extracted from R-admin and R manual.

A package is loaded from a library by the function library(). Thus a library is a directory containing installed packages; the main library is R_HOME/library, but others can be used, for example by setting the environment variable R_LIBS or using the R function .libPaths():

> .libPaths()
[1] "/home/jose/R/x86_64-redhat-linux-gnu-library/3.1"
[2] "/usr/lib64/R/library"                            
[3] "/usr/share/R/library"

The set of packages loaded on startup is by default:

> getOption("defaultPackages")
[1] "datasets"  "utils"     "grDevices" "graphics"  "stats"     "methods" 

To install a new package write:

> install.packages("PackageName", repos = "http://repository_url", dependencies = TRUE)

install.packages can install a source package from a local .tar.gz file by setting argument repos to NULL: this will be selected automatically if the name given is a single .tar.gz file.

install.packages can look in several repositories, specified as a character vector by the argument repos: these can include a CRAN mirror, Bioconductor, Omegahat, R-forge, rforge.net, local archives, local files, …). Function setRepositories() can select amongst those repositories that the R installation is aware of.
The available packates ready to install are shown by calling available.packages().

The command installed.packages finds details of all packages installed. The return value is a matrix with one row per package, row names the package names and column names (currently) “Package”, “LibPath”, “Version”, “Priority”, “Depends”, “Imports”, “LinkingTo”, “Suggests”, “Enhances”, “OS_type”, “License” and “Built”. To see only the name of the installed packages write:

> rownames(installed.packages())

To remove an installed package use the command remove.packages:

> remove.packages("MBCluster.Seq")

To load a package use the command library:

> library("MBCluster.Seq")

The attached packages and extra info can be asked by sessionInfo() command.

source causes R to accept its input from the named file or URL or connection. Input is read and ‘parse’d from that file until the end of the file is reached, then the parsed expressions are evaluated sequentially in the chosen environment.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s