This function attempts to load multiple R packages specified by the user. If a package is not installed, the function can optionally install it before loading. It also provides an option to print the names and versions of the loaded packages.
Arguments
- ...
Character. Names of the packages to be loaded or installed.
- List
Character vector. An alternative or additional way to specify package names as a vector.
- Verbose
Logical. If
TRUE
, prints the names and versions of the loaded packages. Defaults toFALSE
.- InstallMissing
Logical. If
TRUE
(default), missing packages are automatically installed and then loaded.
Value
This function is used for its side effects (loading/installing packages) and does not return any value.
Examples
# Currently loaded packages
(P1 <- IASDT.R::LoadedPackages())
#> [1] "ggplot2" "sf" "car" "carData" "dplyr" "Hmsc"
#> [7] "coda" "rworldmap" "raster" "sp" "png" "IASDT.R"
#> [13] "magrittr" "stats" "graphics" "grDevices" "utils" "datasets"
#> [19] "methods" "base"
LoadPackages(Hmsc)
# Loaded packages after implementing the function
(P2 <- IASDT.R::LoadedPackages())
#> [1] "ggplot2" "sf" "car" "carData" "dplyr" "Hmsc"
#> [7] "coda" "rworldmap" "raster" "sp" "png" "IASDT.R"
#> [13] "magrittr" "stats" "graphics" "grDevices" "utils" "datasets"
#> [19] "methods" "base"
# Which packages were loaded?
setdiff(P2, P1)
#> character(0)
LoadPackages(terra, Verbose = TRUE)
#>
#> The following packages were loaded:
#> >>>>> terra: 1.8-29