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.
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.
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.
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
ggmap
,
9. rayshader, 10. geojsonio,
11. shinyjs,
12. GGally,
13. gridExtra,
14. cartogram,
15. visNetworkUpdated on: 2024-10-17