Is Package Here
is_package_here.RdCheck if required packages are installed locally.
Arguments
- req_package
Character vector of package names to check.
- safer_check
Single logical value. Perform some "safer" checks? If
TRUE, checkings are performed before main code running (see the safer-r project): 1) correctlib_pathargument value 2) required functions and related packages effectively present in local R libraries and 3) R classical operators (like"<-") not overwritten by another package because of the R scope. Must be set toFALSEif this function is used inside another "safer" function to avoid pointless multiple checkings.- lib_path
Vector of characters specifying the absolute pathways of the directories containing the required packages for the function, if not in the default directories. Useful when R packages are not installed in the default directories because of lack of admin rights. More precisely,
lib_pathis passed through thenewargument of.libPaths()so that the new library paths areunique(c(lib_path, .libPaths())). Warning:.libPaths()is restored to the initial paths, after function execution. Ignored ifNULL(default): only the pathways specified by the current.libPaths()are used for package calling.- error_text
Single character string used to add information in error messages returned by the function, notably if the function is inside other functions, which is practical for debugging. Example:
error_text = " INSIDE <PACKAGE_1>::<FUNCTION_1> INSIDE <PACKAGE_2>::<FUNCTION_2>.". IfNULL, converted into"".
Value
An error message if at least one of the checked packages is missing in lib_path, nothing otherwise.
Examples
# Warning: these examples may not work well when using the "Run examples" link
# because of a particular environment. Please, copy-paste in a local environment.
# See also https://safer-r.github.io/saferDev/articles/is_package_here.html
if (FALSE) {
# Example that returns an error
is_package_here(req_package = "nopackage", error_text = " INSIDE P1::F1")
is_package_here(req_package = "ggplot2", lib_path = "C:/Users/gmillot/AppData/Local/R/win-library/4.4") # commented because this example returns an error if the lib_path argument is not an existing directory
}
is_package_here(req_package = "ggplot2")