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, ...)
If repos = NULL
, a character vector of file paths of
windows
.zip files containing binary builds of packages. Source
directories or .tar.gz archives may also be installed, but
some packages need suitable tools installed (see the
Details section).
unix
.tar.gz files. These can be source archives or binary
package archive files (as created by R CMD build --binary
).
On a CRAN build of R for OS X these can be .tgz files
containing binary package archives.
Tilde-expansion will be done on the file paths.
If this is missing or a zero-length character vector, a listbox of available packages is presented where possible in an interactive R session.
.libPaths()
.
"http://cran.us.r-project.org"
. For more details on
supported URL schemes see url
. Can be NULL
to install from local files
(with extension .tar.gz for source packages).
repos
. As with
repos
, can also be NULL
to install from local files.
download.file
.
available.packages
listing packages available at the repositories, or NULL
when
the function makes an internal call to available.packages
.
NULL
(the default) a subdirectory
downloaded_packages
of the session temporary
directory will be used (and the files will be deleted
at the end of the session).
repos = NULL
.
Can also be a character vector, a subset of
c("Depends", "Imports", "LinkingTo", "Suggests", "Enhances")
. Only supported if lib
is 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.
The default, NA
, means
c("Depends", "Imports", "LinkingTo")
.
TRUE
means to use
c("Depends", "Imports", "LinkingTo", "Suggests")
for
pkgs
and
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.
Possible values are (currently) "source"
, "mac.binary"
and "win.binary"
: the binary types can be listed and
downloaded but not installed on other platforms.
The default is the appropriate binary type on Windows and on the
CRAN binary OS X distribution, otherwise "source"
. For
the platforms where binary packages are the default, an alternative
is "both"
which means try binary if available,
otherwise try source. (This will only choose the binary package if
its version number is no older than the source version. In
interactive use it will ask before attempting to install source
packages.)
R CMD INSTALL
. If the character vector has names these
are assumed to identify values for --configure-args 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 --configure-args.
configure.args
for flag
--configure-vars, which is used to set environment variables
for the configure
run.
R CMD INSTALL
.
This is sometimes used to perform additional operations at the end
of the package installation in addition to removing intermediate files.
make
command specified by
Sys.getenv("MAKE", "make")
accepts argument -k -j
Ncpus
.
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.
R CMD INSTALL
for a source package install. E.g.,
c("--html", "--no-multiarch")
.Can also be a named list of character vectors of to be used as additional options, with names the respective package names.
download.file
or to the
functions for binary installs on OS X and Windows (which accept
an argument "lock"
: see the section on Locking).
NULL
.
Ncpus > 1L
.
Finally locking (and restoration on error) can be suppressed by
--no-lock. For an OS X or Windows binary install, no locking is done by
default. Setting argument lock
to TRUE
(it defaults to
the value of getOption("install.lock", FALSE)
) will use
per-directory locking as described for source installs: if the value
is "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
state. 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.pkgs
has length greater than
one and Ncpus > 1
. It makes use of a parallel make
,
so the make
specified (default make
) when R was
built must be capable of supporting make -j n
: GNU make
and dmake
do, but FreeBSD and Solaris make
do not:
if necessary environment variable MAKE can be set for the
current session to select a suitable make
. install.packages
needs to be able to compute all the
dependencies of pkgs
from available
, including if one
element of 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
packages, available
needs to cover both CRAN and
Bioconductor packages.getOption("pkgType")
: this defaults to "source"
apart from under Windows or a CRAN binary distribution for OS X. 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.
windows
Detection of a writable directory is problematic on Windows: see the
Note section.
For source packages 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 R_LIBS).
windows
Using packages with type = "source"
always works on Windows
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 R for Windows FAQ and
you must have the PATH environment variable set up as required
by Rtools.
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
R running at the same time and sharing a library) it will not detect a
problem, but the installation may fail.
You are advised to run update.packages
before
install.packages
to ensure that any already installed
dependencies have their latest versions.
Argument libs_only = TRUE
is supported for source installs and for
Windows binary installs.
For binary installs, the function also 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
options(install.packages.check.source = "no")and should be if there is a partial repository containing only binary files.
update.packages
,
available.packages
,
download.packages
,
installed.packages
,
contrib.url
. See download.file
for how to handle proxies and
other options to monitor file transfers.
INSTALL
, REMOVE
, remove.packages
,
library
, .packages
, read.dcf
The R Installation and Administration manual for how to set up a repository.