Package manager

Install pacman package in R. In order to use the functions that are contained in the pacman package, we have to install and load the package to R:

install.packages("pacman")    # Install pacman package
library("pacman")             # Load pacman package

After running the previous lines of code, we can use the functions provided by the pacman package.

Example 1: Install & load multiple R packages using p_load function

In this example, I will illustrate how to apply the p_load function to load multiple add-on packages in one line of code.

Have a look at the following R syntax:

p_load(ggplot2, dplyr, stringr)   # Install & load packages

After executing the previous code, we have loaded the three packages ggplot2, dplyr, and stringr.

Note that the p_load function also checks whether a package is installed already. If the package is not installed yet, it is installed automatically by the pacman package.

Example 2: Unload multiple R packages using p_unload function

Another useful function of the pacman package is the p_unload function. The p_unload function can be used to detach one or multiple loaded packages from within R.

Let’s apply the p_unload command to unload the three packages ggplot2, dplyr, and stringr that we have loaded before:

p_unload(ggplot2, dplyr, stringr)  # Unload packages

The following packages have been unloaded: ggplot2, dplyr, stringr The previous output of the RStudio console tells us that our three packages were detached.

Example 3: Update Outdated R Packages Using p_update Function

In this example, I will show how to use the p_update function of the pacman package to check for outdated packages AND to update all of these packages.

First, let’s check which of my packages are outdated:

p_update(update = FALSE)  # Check for outdated packages

Second, the pacman package provides an easy solution to how we can update all outdated packages with only one line of R code.

Make sure that you have some time before running the following R code. This may take some time, depending on the number of packages you need to update:

p_update() # Update all packages

R packages for data management

  1. pacman, 2. devtools, 3. remotes, 4. stargazer, 5. readxl, 6. here, 7. rvest, 8. cowplot, 9. ggthemes, 10. ggpubr, 11. plotly, 12. stringr, 13. patchwork, 14. magrittr, 15. DBI , 16. RSQLite, 17. data.table, 18. lubridate

Basic GIS data manipulation

  1. sf, 2. raster, 3. shapefiles, 4. ncdf4, 5. sp

Cartography and data visualization

  1. tidyverse, 2. RColorBrewer, 3. viridis, 4. tmap, 5. leaflet, 6. mapview, 7. cartography, 8. ggmap, 9. rayshader, 10. geojsonio, 11. shinyjs, 12. GGally, 13. gridExtra, 14. cartogram, 15. visNetwork

Spatial statistics

  1. spatial, 2. spatstat, 3. gstat, 4. spdep, 5. geoshape, 6. ggspatial, 7. spdep, 8. geogrid, 9. GISTools

Data sources

  1. OpenStreetMap, 2. rnaturalearth, 3. rnaturalearthdata, 4. rgooglemaps, 5. rastervis, 6. maps, 7. spData, 8. rgeos, 9. jpndistrict, 10. countrycode, 11. tmaptools, 12. DT, 13. usmap, 14. tigris, 15. scales, 16. ggrepel, 17. tidycensus

Updated on: 2024-10-17