Lightweight method to check if an R package is installed

check_pkg_installed(x, ...)

Arguments

x

character string of package or packages to test.

...

additional arguments are ignored.

Value

logical indicating whether each value in x

represents an installed R package.

Details

There are many methods to test for an installed package, this function represents possibly the most gentle and rapid approach. It simply calls system.file(package=""), which checks in the context of the active R session and uses the relevant .libPaths().

This approach does not use require() because that actually loads the package, which can take time and resources.

This approach also does not use installed.packages() which can also take substantial time if many packages are installed on a system.

Examples

check_pkg_installed("methods")
#> methods 
#>    TRUE 

check_pkg_installed(c("jamba",
   "multienrichjam",
   "venndir",
   "methods",
   "blah"))
#>          jamba multienrichjam        venndir        methods           blah 
#>           TRUE           TRUE           TRUE           TRUE          FALSE