Function to check for non-installed or non-functional packages.
Value
A list of length two, with elements 'absent' and 'nonfunc' containing
character vectors with the names of packages in pkgs that are not installed
or are installed but non-functional, with a warning. The elements are
character(0) if all packages in pkgs are present, and if all packages
are installed and functional, respectively.
Package names
The part after the last forward or backward slash is considered to be the
package name if input to pkgs contains such slashes. Therefore package
names, file paths to packages, and full URLs to packages from
GitHub can all be used as input to pkgs, e.g.,
"checkrpkgs", "C:/Users/Eigenaar/AppData/Local/R/win-library/4.5/checkrpkgs",
"https://github.com/JesseAlderliesten/checkrpkgs".
Side effects
Packages are loaded, such that updating them might fail. Restart R to prevent such problems.
Notes
Packages are looked for in the library paths given by .libPaths().
Only the first instance of a package is checked if it occurs more than once, with a warning.
Programming notes
This function uses find.package() and requireNamespace() instead of
utils::installed.packages() because installed.packages does not check if
packages are functional, nor if all needed
dependencies are installed and functional.
In addition, installed.packages() can be slow such that its
help page states that requireNamespace() or
require() should be used instead.
Setting environment variable _R_TRACE_LOADNAMESPACE_ to a numerical value
(e.g., Sys.setenv("_R_TRACE_LOADNAMESPACE_" = 4)) will generate additional
messages on progress for non-standard packages, see the section Tracing in
requireNamespace().
See also
tools::package_dependencies()(packages = "<pkgname>", recursive = TRUE)
for dependencies and
tools::dependsOnPkgs()(pkgs = "<pkgname>", recursive = TRUE)
for reverse dependencies; get_details_pkgs(pkgs = <pkgname>) for more
information about the origin of packages; tools::standard_package_names()
(present since R 4.4.0) for names of the base and recommended packages.
old.packages() and BiocManager::valid() to check for outdated or too new
packages, where the latter takes the currently used version of Bioconductor
(see BiocManager::version()) into account.
options("defaultPackages") for names of packages that are attached by
default when R starts up; loadedNamespaces() and utils::sessionInfo()
for names of packages that are currently loaded.
The vignette Instructions about R packages:
vignette("r_pkgs", package = "checkrpkgs").
Other functions to get information about packages:
get_details_pkgs()
Examples
check_pkgs(pkgs = c("base", "grid"), quietly = FALSE)
#> $absent
#> character(0)
#>
#> $nonfunc
#> character(0)
#>
non_existent_pkgs <- c("yz/wx/abcdef4", "wx/abcdef3", "abcdef2", "abcdef1")
check_pkgs(non_existent_pkgs, quietly = FALSE)
#> Warning: non-installed packages: 'yz/wx/abcdef4', 'wx/abcdef3', 'abcdef2', 'abcdef1'
#> $absent
#> [1] "yz/wx/abcdef4" "wx/abcdef3" "abcdef2" "abcdef1"
#>
#> $nonfunc
#> character(0)
#>
check_pkgs(non_existent_pkgs, quietly = TRUE)
#> Warning: non-installed packages: 'yz/wx/abcdef4', 'wx/abcdef3', 'abcdef2', 'abcdef1'
#> $absent
#> [1] "yz/wx/abcdef4" "wx/abcdef3" "abcdef2" "abcdef1"
#>
#> $nonfunc
#> character(0)
#>
check_pkgs(pkgs = c(non_existent_pkgs, "utils"), quietly = FALSE)
#> Warning: non-installed packages: 'yz/wx/abcdef4', 'wx/abcdef3', 'abcdef2', 'abcdef1'
#> $absent
#> [1] "yz/wx/abcdef4" "wx/abcdef3" "abcdef2" "abcdef1"
#>
#> $nonfunc
#> character(0)
#>