Rev 61239 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/utils/man/install.packages.Rd% Part of the R package, http://www.R-project.org% Copyright 1995-2012 R Core Team% Distributed under GPL 2 or later\name{install.packages}\alias{install.packages}\title{Install Packages from Repositories or Local Files}\description{Download and install packages from CRAN-like repositories or fromlocal files.}\usage{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),libs_only = FALSE, INSTALL_opts, \dots)}\arguments{\item{pkgs}{character vector of the names of packages whosecurrent versions should be downloaded from the repositories.If \code{repos = NULL}, a character vector of file paths of#ifdef windows\file{.zip} files containing binary builds of packages. Sourcedirectories or \file{.tar.gz} archives may also be installed, butsome packages need suitable tools installed (see the\sQuote{Details} section).#endif#ifdef unix\file{.tar.gz} files. These can be source archives or binarypackage archive files (as created by \command{R CMD build --binary}).On a CRAN build of \R for Mac OS X these can be \file{.tgz} filescontaining binary package archives.Tilde-expansion will be done on the file paths.#endifIf this is missing or a zero-length character vector, a listbox ofavailable packages is presented where possible in an interactive \Rsession.}\item{lib}{character vector giving the library directories where toinstall the packages. Recycled as needed. If missing, defaults tothe first element of \code{\link{.libPaths}()}.}\item{repos}{character vector, the base URL(s) of the repositoriesto use, e.g., the URL of a CRAN mirror such as\code{"http://cran.us.r-project.org"}.Can be \code{NULL} to install from local files(with extension \file{.tar.gz} for source packages).}\item{contriburl}{URL(s) of the contrib sections of the repositories. Use thisargument if your repository mirror is incomplete, e.g., becauseyou burned only the \file{contrib} section on a CD, or only havebinary packages. Overrides argument \code{repos}. As with\code{repos}, can also be \code{NULL} to install from local files.}\item{method}{download method, see \code{\link{download.file}}.}\item{available}{an object as returned by \code{\link{available.packages}}listing packages available at the repositories, or \code{NULL} whenthe function makes an internal call to \code{available.packages}.}\item{destdir}{directory where downloaded packages are stored. If it is\code{NULL} (the default) a subdirectory\code{downloaded_packages} of the session temporarydirectory will be used (and the files will be deletedat the end of the session).}\item{dependencies}{logical indicating to also install uninstalledpackages which these packages depend on/link to/import/suggest(and so on recursively). Not used if \code{repos = NULL}.Can also be a character vector, a subset of\code{c("Depends", "Imports", "LinkingTo", "Suggests", "Enhances")}.Only supported if \code{lib} is of length one (or missing),so it is unambiguous where to install the dependent packages. Ifthis is not the case it is ignored, with a warning.The default, \code{NA}, means\code{c("Depends", "Imports", "LinkingTo")}.\code{TRUE} means (as from \R 2.15.0) to use\code{c("Depends", "Imports", "LinkingTo", "Suggests")} for\code{pkgs} and\code{c("Depends", "Imports", "LinkingTo")} for added dependencies:this installs all the packages needed to run \code{pkgs}, theirexamples, tests and vignettes (if the package author specified themcorrectly).}\item{type}{character, indicating the type of package to download andinstall.Possible values are \code{"source"}, \code{"mac.binary.leopard"} and\code{"win.binary"}: the binary types can be listed and downloadedbut not installed on other platforms.The default is the appropriate binary type on Windows and onthe CRAN binary Mac OS X distribution, otherwise \code{"source"}.For the platforms where binary packages are the default, analternative is \code{"both"} which means \sQuote{try binary ifavailable, otherwise try source}. (This will only choose thebinary package if its version number is no older than the sourceversion.)}\item{configure.args}{(not used on Windows) a character vector or a named list. If acharacter vector with no names is supplied, the elements areconcatenated into a single string (separated by a space) and used asthe value for the \option{--configure-args} flag in the call to\command{R CMD INSTALL}. If the character vector has names theseare assumed to identify values for \option{--configure-args} forindividual packages. This allows one to specify settings for anentire collection of packages which will be used if any of thosepackages are to be installed. (These settings can therefore bere-used and act as default settings.)A named list can be used also to the same effect, and thatallows multi-element character strings for each packagewhich are concatenated to a single string to be used as thevalue for \option{--configure-args}.}\item{configure.vars}{(not used on Windows) analogous to \code{configure.args} for flag\option{--configure-vars}, which is used to set environment variablesfor the \command{configure} run.}\item{clean}{a logical value indicating whether to specifyto add the \option{--clean} flag to the call to\command{R CMD INSTALL}.This is sometimes used to perform additional operations at the endof the package installation in addition to removing intermediate files.}\item{Ncpus}{The number of parallel processes to use for a parallelinstall of more than one source package. Values greater than oneare supported if the \command{make} command specified by\code{Sys.getenv("MAKE", "make")} accepts argument \code{-k -j\var{Ncpus}}.}\item{libs_only}{a logical value: should the \option{--libs-only} option be used toinstall only additional sub-architectures? (See also\code{INSTALL_opts}.) This can also be used on Windows to installjust the DLL(s) from a binary package, e.g. to add 64-bit DLLs to a32-bit install.}\item{INSTALL_opts}{an optional character vector of additional option(s) to be passed to\command{R CMD INSTALL} for a source package install. E.g.\code{c("--html", "--no-multiarch")}.}\item{\dots}{Arguments to be passed to \code{\link{download.file}} (e.g.\code{quiet = TRUE}), or to the functions for binary installs on MacOS X and Windows (which accept an argument \code{"lock"}: see thesection on \sQuote{Locking}).}}\details{\R packages are primarily distributed as \emph{source} packages, but\emph{binary} packages (a packaging up of the installed package) arealso supported, and the type most commonly used on Windows and fromthe CRAN distribution for Mac OS X. This function can install eithertype where supported, either by downloading a file from a repositoryor from a local file. The default type is given by\code{\link{getOption}("pkgType")}: this defaults to \code{"source"}apart from under Windows or a CRAN binary distribution for Mac OS X.This is the main function to install packages. It takesa vector of names and a destination library, downloads the packagesfrom the repositories and installs them. (If the library is omittedit defaults to the first directory in \code{.libPaths()}, with amessage if there is more than one.) If \code{lib} is omitted or is oflength one and is not a (group) writable directory, the code offersto create a personal library tree (the first element of\code{Sys.getenv("R_LIBS_USER")}) and install there.#ifdef windowsDetection of a writable directory is problematic on Windows: see the\sQuote{Note} section.#endifFor source packages from a repository an attempt is made toinstall the packages in an order that respects their dependencies.This does assume that all the entries in \code{lib} are on the defaultlibrary path for installs (set by \env{R_LIBS}).#ifdef windowsUsing packages with \code{type = "source"} always works on Windowsprovided the package contains no C/C++/Fortran code that needscompilation. Otherwise you will need to have installed the Rtoolscollection as described in the \sQuote{R for Windows FAQ} \emph{and}you must have the \env{PATH} environment variable set up as requiredby Rtools.When installing a binary package, \code{install.packages} will abortthe install if it detects that the package is already installed and iscurrently in use. In some circumstances (e.g. multiple instances of\R running at the same time and sharing a library) it will not detect aproblem, but the installation may fail.#endifYou are advised to run \code{update.packages} before\code{install.packages} to ensure that any already installeddependencies have their latest versions.Argument \code{libs_only = TRUE} is supported for source installs and forWindows binary installs.For binary installs, the function also checks for the availability ofa source package on the same repository, and reports if the sourcepackage has a later version, or is available but no binary versionis. This check can be suppressed by\preformatted{ options(install.packages.check.source = "no")}and should be if there is a partial repository containing only binaryfiles.}\value{Invisible \code{NULL}.}\section{Locking}{There are various options for locking: these differ between source andbinary installs.By default for a source install, the library directory is\sQuote{locked} by creating a directory \file{00LOCK} within it. Thishas two purposes: it prevents any other process installing into thatlibrary concurrently, and is used to store any previous version of thepackage to restore on error. A finer-grained locking is provided bythe option \option{--pkglock} which creates a separate lock for eachpackage: this allows enough freedom for parallelinstallation. Per-package locking is the default when installing asingle package, and for multiple packages when \code{Ncpus > 1L}.Finally locking (and restoration on error) can be suppressed by\option{--no-lock}.% and also options(install.lock = FALSE) in an \R startup file.For a Mac OS X or Windows binary install, no locking is done bydefault. Setting argument \code{lock} to \code{TRUE} (it defaults tothe value of \code{\link{getOption}("install.lock", FALSE)}) will useper-directory locking as described for source installs: if the valueis \code{"pkglock"} per-package locking will be used.If package locking is used on Windows with \code{libs_only = TRUE} andthe installation fails, the package will be restored to its previousstate.Note that it is possible for the package installation to fail so badlythat the lock directory is not removed: this inhibits any furtherinstalls to the library directory (or for \code{--pkglock}, of thepackage) until the lock directory is removed manually.}\section{Parallel installs}{Parallel installs are attempted if \code{pkgs} has length greater thanone and \code{Ncpus > 1}. It makes use of a parallel \command{make},so the \code{make} specified (default \command{make}) when \R wasbuilt must be capable of supporting \code{make -j \var{n}}: GNU makeand \command{dmake} do, but FreeBSD and Solaris \command{make} do not:if necessary environment variable \env{MAKE} can be set for thecurrent session to select a suitable \command{make}.\code{install.packages} needs to be able to compute all thedependencies of \code{pkgs} from \code{available}, including if oneelement of \code{pkgs} depends indirectly on another. This means thatif for example you are installing \acronym{CRAN} packages which dependon Bioconductor packages which in turn depend on \acronym{CRAN}packages, \code{available} needs to cover both \acronym{CRAN} andBioconductor packages.}#ifdef unix\note{Some binary distributions of \R have \code{INSTALL} in a separatebundle, e.g. an \code{R-devel} RPM. \code{install.packages} willgive an error if called with \code{type = "source"} on such a system.Some binary distributions of \R can be installed on a machine without thetools needed to install packages: the remedy is to do a completeinstall of \R which should bring in all those tools as dependencies.}#endif#ifdef windows\note{\code{install.packages} tries to detect if you have write permissionon the library directories specified, but Windows reports unreliably.If there is only one library directory (the default), \R tries tofind out by creating a test directory, but even this need not be thewhole story. Under Windows Vista and later you may have permission towrite in a library directory but lack permission to write binary files(such as \file{.dll} files) there. See the \sQuote{R for Windows FAQ}for workarounds.}#endif\seealso{\code{\link{update.packages}},\code{\link{available.packages}},\code{\link{download.packages}},\code{\link{installed.packages}},\code{\link{contrib.url}}.See \code{\link{download.file}} for how to handle proxies andother options to monitor file transfers.\code{\link{INSTALL}}, \code{\link{REMOVE}}, \code{\link{remove.packages}},\code{\link{library}}, \code{\link{.packages}}, \code{\link{read.dcf}}The \sQuote{R Installation and Administration} manual for how toset up a repository.}\examples{\dontrun{## A Linux example for Fedora's layoutinstall.packages(c("ncdf4", "RNetCDF"),configure.args = c(RNetCDF = "--with-netcdf-include=/usr/include/udunits2"))}}\keyword{utilities}