Check for presence of a package
checkPkgs.Rd
This function efficiently checks for the presence of a package
without loading it (unlike library()
or require()
.
This is useful to force yourself to use the package::function()
syntax for addressing functions; you can make sure required packages
are installed, but their namespace won't attach to the search path.
Arguments
- ...
A series of packages. If the packages are named, the names are the package names, and the values are the minimum required package versions (see the second example).
- install
Whether to install missing packages from
repos
.- load
Whether to load packages (which is exactly not the point of this function, but hey, YMMV).
- repos
The repository to use if installing packages; default is the RStudio repository.
Examples
# \donttest{
squids::checkPkgs('base');
### Require a specific version
squids::checkPkgs(squids = "25.13.1");
#> Error in squids::checkPkgs(squids = "25.13.1"): Of package(s) 'squids', you need at least versions 25.13.1, respectively. Install those with:
#>
#> install.packages(c('squids'));
### This will show the error message
tryCatch(
squids::checkPkgs(
base = "99",
stats = "42.5",
squids = 100
),
error = print
);
#> <simpleError in squids::checkPkgs(base = "99", stats = "42.5", squids = 100): Of package(s) 'base', 'stats' & 'squids', you need at least versions 99, 42.5 & 100, respectively. Install those with:
#>
#> install.packages(c('base', 'stats', 'squids'));
#> >
# }