is_package_here
is_package_here.Rd
Check 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 https://github.com/safer-r): 1) correct lib_path argument value 2) required functions and related packages effectively present in local R lybraries and 3) R classical operators (like "<-") not overwritten by another package because of the R scope. Must be set to FALSE if this fonction 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 package are not installed in the default directories because of lack of admin rights. More precisely, lib_path is passed through the new argument of .libPaths() so that the new library paths are unique(c(new, .Library.site, .Library)). Warning: .libPaths() is restored to the initial paths, after function execution. Ignored if NULL (default) or if the safer_check argument is FALSE: 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>.". If NULL, converted into "".
Value
An error message if at least one of the checked packages is missing in lib_path, nothing otherwise.
Examples
if (FALSE) # Example that return 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
#> Error:
#>
#> ================
#>
#> ERROR IN saferDev::is_package_here().
#>
#> THE DIRECTORY PATH INDICATED IN THE lib_path ARGUMENT DOES NOT EXIST:
#> C:/Users/gmillot/AppData/Local/R/win-library/4.4
#>
#> ================
#>
is_package_here(req_package = "ggplot2")