This function efficiently checks for the presence of a package
without loading it (unlike
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.
checkPkgs( ..., install = FALSE, load = FALSE, repos = "https://cran.rstudio.com" )
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).
Whether to install missing packages from
Whether to load packages (which is exactly not the point of this function, but hey, YMMV).
The repository to use if installing packages; default is the RStudio repository.
Invisibly, a vector of the available packages.
metabefor::checkPkgs('base'); ### Require a version metabefor::checkPkgs(metabefor = "0.1.0"); ### This will show the error message tryCatch( metabefor::checkPkgs( base = "99", stats = "42.5", ufs = 20 ), error = print ); #> <simpleError in metabefor::checkPkgs(base = "99", stats = "42.5", ufs = 20): Of package(s) 'base', 'stats' & 'ufs', you need at least versions 99, 42.5 & 20, respectively. Install those with: #> #> install.packages(c('base', 'stats' & 'ufs')); #> >