Skip to contents

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.

Usage

LoadPackages(..., List = NULL, Verbose = FALSE, InstallMissing = TRUE)

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 to FALSE.

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.

Author

Ahmed El-Gabbas

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