Install Packages from Repositories or Local Files
Download and install packages from CRAN-like repositories or from local files.
install.packages(pkgs, lib, repos = getOption("repos"), contriburl = contrib.url(repos, type), method, available = NULL, destdir = NULL, dependencies = NA, type = getOption("pkgType"), configure.args = getOption("configure.args"), configure.vars = getOption("configure.vars"), clean = FALSE, Ncpus = getOption("Ncpus", 1L), verbose = getOption("verbose"), libs_only = FALSE, INSTALL_opts, quiet = FALSE, keep_outputs = FALSE, ...)
- character vector of the names of packages whose
current versions should be downloaded from the repositories.
repos = NULL, a character vector of #ifdef windows file paths of
.zipfiles containing binary builds of packages. (
file://URLs are also accepted and the files will be downloaded and installed from local copies.) Source directories or file paths or URLs of archives may be specified with
type = "source", but some packages need suitable tools installed (see the
Detailssection). #endif #ifdef unix file paths. These can be source directories or archives or binary package archive files (as created by R CMD build --binary). (
file://URLs are also accepted and the files will be downloaded and installed from local copies.) On a CRAN build of Rfor OS X these can be
.tgzfiles containing binary package archives. Tilde-expansion will be done on file paths. #endif
If this is missing or a zero-length character vector, a listbox of available packages is presented where possible in an interactive Rsession.
- character vector giving the library directories where to
install the packages. Recycled as needed. If missing, defaults to
the first element of
- character vector, the base URL(s) of the repositories
to use, e.g., the URL of a CRAN mirror such as
"http://cran.us.r-project.org". For more details on supported URL schemes see
NULLto install from local files, directories or URLs: this will be inferred by extension from
pkgsif of length one.
- URL(s) of the contrib sections of the repositories. Use this
argument if your repository mirror is incomplete, e.g., because
you burned only the
contribsection on a CD, or only have binary packages. Overrides argument
repos. Incompatible with
type = "both".
- download method, see
download.file. Unused if a non-
- a matrix as returned by
available.packageslisting packages available at the repositories, or
NULLwhen the function makes an internal call to
available.packages. Incompatible with
type = "both".
- directory where downloaded packages are stored. If it is
NULL(the default) a subdirectory
downloaded_packagesof the session temporary directory will be used (and the files will be deleted at the end of the session).
- logical indicating whether to also install
uninstalled packages which these packages depend on/link
to/import/suggest (and so on recursively). Not used if
repos = NULL. Can also be a character vector, a subset of
c("Depends", "Imports", "LinkingTo", "Suggests", "Enhances").
Only supported if
libis of length one (or missing), so it is unambiguous where to install the dependent packages. If this is not the case it is ignored, with a warning.
c("Depends", "Imports", "LinkingTo").
TRUEmeans to use
c("Depends", "Imports", "LinkingTo", "Suggests")for
c("Depends", "Imports", "LinkingTo")for added dependencies: this installs all the packages needed to run
pkgs, their examples, tests and vignettes (if the package author specified them correctly).
In all of these,
"LinkingTo"is omitted for binary packages.
- character, indicating the type of package to download and
install. Will be
"source"except on Windows and some OS X builds: see the section on
Binary packagesfor those.
- (Used only for source installs.) A character vector or a named list.
If a character vector with no names is supplied, the elements are
concatenated into a single string (separated by a space) and used as
the value for the flag in the call to
R CMD INSTALL. If the character vector has names these are assumed to identify values for for individual packages. This allows one to specify settings for an entire collection of packages which will be used if any of those packages are to be installed. (These settings can therefore be re-used and act as default settings.)
A named list can be used also to the same effect, and that allows multi-element character strings for each package which are concatenated to a single string to be used as the value for .
- (Used only for source installs.) Analogous to
configure.argsfor flag , which is used to set environment variables for the
- a logical value indicating whether to add the
flag to the call to
R CMD INSTALL. This is sometimes used to perform additional operations at the end of the package installation in addition to removing intermediate files.
- the number of parallel processes to use for a parallel
install of more than one source package. Values greater than one
are supported if the
make command specified by
Sys.getenv("MAKE", "make")accepts argument
-k -j Ncpus.
- a logical indicating if some
progress reportshould be given.
- a logical value: should the option be used to
install only additional sub-architectures for source installs? (See also
INSTALL_opts.) This can also be used on Windows to install just the DLL(s) from a binary package, e.g.
to add 64-bit DLLs to a 32-bit install.
- an optional character vector of additional option(s) to be passed to
R CMD INSTALL for a source package install. E.g.,
Can also be a named list of character vectors to be used as additional options, with names the respective package names.
- logical: if true, reduce the amount of output.
- a logical: if true, keep the outputs from installing source packages
in the current working directory, with the names of the output files
the package names with
.outappended. Alternatively, a character string giving the directory in which to save the outputs. Ignored when installing from local files.
- Arguments to be passed to
download.fileor to the functions for binary installs on OS X and Windows (which accept an argument
"lock": see the section on
This is the main function to install packages. It takes a vector of
names and a destination library, downloads the packages from the
repositories and installs them. (If the library is omitted it
defaults to the first directory in
.libPaths(), with a message
if there is more than one.) If
lib is omitted or is of length
one and is not a (group) writable directory, in interactive use the
code offers to create a personal library tree (the first element of
Sys.getenv("R_LIBS_USER")) and install there.
Detection of a writable directory is problematic on Windows: see the
For installs from a repository an attempt is made to install the
packages in an order that respects their dependencies. This does
assume that all the entries in
lib are on the default library
path for installs (set by environment variable
You are advised to run
install.packages to ensure that any already installed
dependencies have their latest versions.
- Some binary distributions of Rhave
INSTALLin a separate bundle, e.g.
install.packageswill give an error if called with
type = "source"on such a system.
Some binary Linux distributions of Rcan be installed on a machine without the tools needed to install packages: a possible remedy is to do a complete install of Rwhich should bring in all those tools as dependencies.
install.packagestries to detect if you have write permission on the library directories specified, but Windows reports unreliably. If there is only one library directory (the default), Rtries to find out by creating a test directory, but even this need not be the whole story: you may have permission to write in a library directory but lack permission to write binary files (such as
.dllfiles) there. See the R for Windows FAQfor workarounds.
This section applies only to platforms where binary packages are available: Windows and CRAN builds for OS X. Rpackages are primarily distributed as source packages, but binary packages (a packaging up of the installed package) are also supported, and the type most commonly used on Windows and by the CRAN builds for OS X. This function can install either type, either by downloading a file from a repository or from a local file.
Possible values of
type are (currently)
"win.binary": the appropriate binary type where
supported can also be selected as
For a binary install from a repository, the function checks for the
availability of a source package on the same repository, and reports
if the source package has a later version, or is available but no
binary version is. This check can be suppressed by using
options(install.packages.check.source = "no")
and should be if there is a partial repository containing only binary
An alternative (and the current default) is
"both" which means
type = "both" will be silently changed to
available is specified.
Using packages with
type = "source" always works provided the
package contains no C/C++/Fortran code that needs compilation.
Otherwise you will need to have installed the Rtools
collection as described in the
For a 32/64-bit installation of Ron Windows, a small minority of
packages with compiled code need either
INSTALL_opts = "--merge-multiarch" for a
source installation. (It is safe to always set the latter when
installing from a repository or tarballs, although it will be a little
When installing a binary package,
install.packages will abort
the install if it detects that the package is already installed and is
currently in use. In some circumstances (e.g., multiple instances of
Rrunning at the same time and sharing a library) it will not detect a
problem, but the installation may fail as Windows locks files in use.
Otherwise, on OS X you otherwise need to have installed the
There are various options for locking: these differ between source and binary installs.
By default for a source install, the library directory is
Ncpus > 1L.
Finally locking (and restoration on error) can be suppressed by
For an OS X or Windows binary install, no locking is done by
default. Setting argument
TRUE (it defaults to
the value of
getOption("install.lock", FALSE)) will use
per-directory locking as described for source installs: if the value
"pkglock" per-package locking will be used.
If package locking is used on Windows with
libs_only = TRUE and
the installation fails, the package will be restored to its previous
Note that it is possible for the package installation to fail so badly
that the lock directory is not removed: this inhibits any further
installs to the library directory (or for
--pkglock, of the
package) until the lock directory is removed manually.
Parallel installs are attempted if
pkgs has length greater than
Ncpus > 1. It makes use of a parallel
make specified (default
make -j n: GNU make,
install.packages needs to be able to compute all the
available, including if one
pkgs depends indirectly on another. This means that
if for example you are installing CRAN packages which depend
on Bioconductor packages which in turn depend on CRAN
available needs to cover both CRAN and
download.file for how to handle proxies and
other options to monitor file transfers.
## A Linux example for Fedora's layout of udunits2 headers. install.packages(c("ncdf4", "RNetCDF"), configure.args = c(RNetCDF = "--with-netcdf-include=/usr/include/udunits2"))