Written and maintained by CASRAI Editorial Board
Published · Last updated
On this page
Short answer: pacman is an R package, not the Arch Linux package manager of the same name. Its main function, p_load(), is a wrapper for library() and require(): it checks whether each named package is installed, tries to install it from CRAN (and other repositories in pacman’s repository list) if not, and then loads it. Because it installs silently, research scripts that use it should also record package versions (see below). Facts on this page were read from the CRAN package page, the CRAN reference manual and the package’s GitHub README and vignette on 2026-11-08.
What pacman is used for in research
The CRAN description of pacman is “tools that make add-on package tasks in R easier”, wrapping lower-level library and package functions under more intuitive names. CRAN lists version 0.5.1, published 2019-03-11, licensed GPL-2, requiring R 3.5.0 or later and importing remotes, methods, stats and utils. The maintainer is Tyler Rinker.
In a research script the practical use is a single line at the top that loads every package the analysis needs, installing any that are missing on the machine running it. That is convenient when a script is shared with collaborators or run on a new computer, for example alongside tools covered in our guides to janitor, readxl and patchwork.
Install or access (official source only)
Install from CRAN:
install.packages("pacman")
The development version is hosted on GitHub at trinker/pacman. The README installs it through devtools, and on Windows that requires Rtools to be installed first. Most research use only needs the CRAN release.
Step-by-step: load packages with p_load()
- Install pacman once with
install.packages("pacman"). - Load several packages in one call. Names do not need quotes:
pacman::p_load(XML, devtools, RCurl)(the vignette example). - Check what is attached with
p_loaded(), as in the reference manual examples. - Unload a package with
p_unload(lattice).p_unload("all")unloads every non-base package, andnegate = TRUEunloads all except those listed. Base packages are not unloaded.
The p_load() signature
The CRAN reference manual gives: p_load(..., char, install = TRUE, update = getOption("pac_update"), character.only = FALSE).
...: package names.char: a character vector of package names; use it when callingp_loadfrom inside a function.install: ifTRUE(the default), a package not found in the library is installed.update: ifTRUE, attempts to update all out-of-date packages. The default reads thepac_updateoption, which you can set in your.Rprofile.character.only: ifTRUE,p_loadaccepts a single input that is a character vector of package names.
Other functions in the vignette
p_load_gh("trinker/regexr", "hadley/[email protected]")installs and loads from GitHub using username/repo[/subdir][@ref|#pull] syntax; it wraps devtools’install_github.p_update()updates out-of-date packages;p_update(FALSE)only lists them.p_temp(pkg)installs a package for the current session only;p_isinstalled()andp_isloaded()check status.
pacman versus library() and require()
| Task | Base R pattern | pacman |
|---|---|---|
| Load one installed package | library(readxl) |
pacman::p_load(readxl) |
| Load a package and install it if missing | if (!requireNamespace("readxl", quietly = TRUE)) install.packages("readxl"); library(readxl) |
pacman::p_load(readxl) |
| Load several packages | One library() call per package |
pacman::p_load(readxl, janitor, patchwork) |
Output and how to read it
p_load() is called for its side effect: afterwards the packages are attached to the search path, exactly as if you had called library(). Use p_loaded() to list what is attached and p_isinstalled() to test installation. If a package had to be installed, R’s normal install.packages messages appear in the console.
Reproducibility: record versions
Because install = TRUE is the default, p_load() will fetch whatever version of a missing package is current on the repository at that moment. It does not pin versions, so two collaborators can end up with different versions of the same package. For a published analysis, pair it with a version record such as sessionInfo() output saved with your results, or use one of the tools in the table below. See also our guide to the Positron IDE and to fitting mixed models with lmer for analysis workflows where package versions matter.
Troubleshooting
| Symptom | What the documentation says |
|---|---|
| Error when passing a character vector | Use char = your_vector, or character.only = TRUE with a single character-vector input, as described in the reference manual. |
| Calling p_load inside a function fails | The manual recommends passing the character vector to the char argument directly. |
| A GitHub package will not install | p_load_gh() wraps devtools’ install_github; check the username/repo[@ref] string, and on Windows that Rtools is installed for development builds. |
| Package is not on CRAN | p_load() tries CRAN and the other repositories in pacman’s repository list; for anything else use p_load_gh() or install it by other means first. |
| You do not want automatic installation | Set install = FALSE. |
Free alternatives
| Tool | What it does (CRAN description) | Version and date read |
|---|---|---|
Base R library(), require(), install.packages() |
Load and install packages; pacman’s p_load wraps library and require. |
Part of R |
| renv | “A dependency management toolkit for R”: project-local libraries, a lockfile, and restore. | 1.3.1, published 2026-10-06 |
| groundhog | Loads the package versions available at a date you give, via groundhog.library(), from CRAN, GitHub or GitLab. |
3.4.0, published 2026-01-10 |
Unlike pacman, renv and groundhog are aimed at reproducibility (fixing versions) rather than convenience loading.
FAQ
What is the pacman R package?
An R package from CRAN (version 0.5.1, published 2019-03-11) that wraps package loading, installing, updating and unloading under short function names such as p_load().
How do I install the pacman R package?
Run install.packages("pacman"), then library(pacman) or call functions with pacman::.
Does p_load install packages automatically?
Yes. With the default install = TRUE, a package not found locally is installed from CRAN or another repository in pacman’s list, then loaded.
Is this the same as the pacman command on Arch Linux?
No. The Arch Linux package manager shares the name but is unrelated to this R package.







