| pkg_attach {xfun} | R Documentation |
pkg_attach() is a vectorized version of library() over
the package argument to attach multiple packages in a single function
call. pkg_load() is a vectorized version of
requireNamespace() to load packages (without attaching them).
The functions pkg_attach2() and pkg_load2() are wrappers of
pkg_attach(install = TRUE) and pkg_load(install = TRUE),
respectively. loadable() is an abbreviation of
requireNamespace(quietly = TRUE).
pkg_attach(..., install = FALSE) pkg_load(..., error = TRUE, install = FALSE) loadable(pkg, strict = TRUE) pkg_attach2(...) pkg_load2(...)
... |
Package names (character vectors, and must always be quoted). |
install |
Whether to automatically install packages that are not
available using |
error |
Whether to signal an error when certain packages cannot be loaded. |
pkg |
A single package name. |
strict |
If |
These are convenience functions that aim to solve these common problems: (1)
We often need to attach or load multiple packages, and it is tedious to type
several library() calls; (2) We are likely to want to install the
packages when attaching/loading them but they have not been installed.
pkg_attach() returns NULL invisibly. pkg_load()
returns a logical vector, indicating whether the packages can be loaded.
library(xfun)
pkg_attach("stats", "graphics")
# pkg_attach2('servr') # automatically install servr if it is not installed
(pkg_load("stats", "graphics"))