Rev 87961 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/base/man/find.package.Rd% Part of the R package, https://www.R-project.org% Copyright 1995-2018 R Core Team% Distributed under GPL 2 or later\name{find.package}\alias{find.package}\alias{path.package}\alias{packageNotFoundError}\title{Find Packages}\description{Find the paths to one or more packages.}\usage{find.package(package, lib.loc = NULL, quiet = FALSE,verbose = getOption("verbose"))path.package(package, quiet = FALSE)packageNotFoundError(package, lib.loc, call = NULL)}\arguments{\item{package}{character vector: the names of packages.}\item{lib.loc}{a character vector describing the location of \Rlibrary trees to search through, or \code{NULL}. The default valueof \code{NULL} corresponds to checking the loaded namespace, thenall libraries currently known in \code{\link{.libPaths}()}.}\item{quiet}{logical. Should this not give warnings or an errorif the package is not found?}\item{verbose}{a logical. If \code{TRUE}, additional diagnostics areprinted, notably when a package is found more than once.}\item{call}{call expression.}}\details{\code{find.package} returns the paths to the locations where thegiven packages are found. If \code{lib.loc} is \code{NULL}, thenloaded namespaces are searched before the libraries. If a package isfound more than once, the first match is used. Unless \code{quiet =TRUE} a warning will be given about the named packages which are notfound, and an error if none are. If \code{verbose} is true, warningsabout packages found more than once are given. For a package to bereturned it must contain a either a \file{Meta} subdirectory or a\file{DESCRIPTION} file containing a valid \code{version} field, butit need not be installed (it could be a source package if\code{lib.loc} was set suitably).\code{find.package} is not usually the right tool to find out if apackage is available for use: the only way to do that is to use\code{\link{require}} to try to load it. It need not be installed forthe correct platform, it might have a version requirement not met bythe running version of \R, there might be dependencies which are notavailable, \dots.\code{path.package} returns the paths from which the named packageswere loaded, or if none were named, for all currently attached packages.Unless \code{quiet = TRUE} it will warn if some of the packages namedare not attached, and give an error if none are.\code{packageNotFoundError} creates an error condition object of class\code{packageNotFoundError} for signaling errors. The condition objectcontains the fields \code{package} and \code{lib.loc}.}\seealso{\code{\link{path.expand}} and \code{\link{normalizePath}} for pathstandardization.}\value{A character vector of paths of package directories.}\examples{try(find.package("knitr"))## will not give an error, maybe a warning about *all* locations it is found:find.package("kitty", quiet=TRUE, verbose=TRUE)## Find all .libPaths() entries a package is found:findPkgAll <- function(pkg)unlist(lapply(.libPaths(), function(lib)find.package(pkg, lib, quiet=TRUE, verbose=FALSE)))findPkgAll("MASS")findPkgAll("knitr")}\keyword{file}