Package Errors

Package not installed

Matches: there is no package called '([^']+)'

WHAT THIS ERROR MEANS

The package you're trying to load hasn't been installed on your system yet.

WHY IT HAPPENS — 4 COMMON CAUSES

1. It genuinely was never installed

install.packages() and library() are separate steps, and copying a script from elsewhere brings the library() calls without the installs. This is the ordinary case and the easiest to fix.

2. The install failed but looked like it worked

Packages needing compilation can emit pages of output ending in a non-fatal-looking warning while leaving nothing installed. The message "installation of package had non-zero exit status" is the one that matters, and it is easy to miss in the scroll.

3. R was upgraded and the library moved

R keeps separate library directories per minor version. Moving from 4.3 to 4.4 gives you an empty library, and every package needs reinstalling even though the old files are still on disk.

4. It is a Bioconductor or GitHub package

install.packages() only reaches CRAN. Bioconductor packages need BiocManager::install(), and GitHub-only packages need remotes::install_github() or pak::pak().

HOW TO DIAGNOSE WHICH ONE IT IS

  1. Confirm what R can see: "dplyr" %in% rownames(installed.packages()).
  2. Check where it is looking with .libPaths() — more than one entry means the package may be installed somewhere R is not reading first.
  3. Re-run the install and read the tail of the output for "non-zero exit status" rather than assuming success.
  4. After an R upgrade, compare .libPaths() against the old version’s directory to confirm the library really did change.
  5. For a package that is not on CRAN, check its README for the correct installer.

HOW TO FIX IT

1. Install the package first with install.packages('package_name').

2. Then load it with library(package_name).

3. Check for typos in the package name.

CODE EXAMPLES

BAD — THIS CAUSES THE ERROR
library(tidyvers)  # typo!
GOOD — CORRECT APPROACH
install.packages("tidyverse")
library(tidyverse)

MORE SCENARIOS THAT TRIGGER THIS

A package that is not on CRAN

BAD
install.packages("DESeq2")
# Warning: package ‘DESeq2’ is not available for this version of R
GOOD
install.packages("BiocManager")
BiocManager::install("DESeq2")

"not available for this version of R" almost always means wrong repository rather than genuine incompatibility. Bioconductor packages are never on CRAN.

Making a script install what it needs

BAD
library(tidyverse)
library(janitor)
# fails on any machine that lacks them
GOOD
required <- c("tidyverse", "janitor")
missing <- setdiff(required, rownames(installed.packages()))
if (length(missing)) install.packages(missing)

library(tidyverse)
library(janitor)

Useful for scripts that travel between machines. For anything reproducible, renv is the better answer — it records exact versions in a lockfile rather than installing whatever is current.

PACKAGE-SPECIFIC NOTES

On Linux, packages that need compilation also need system libraries — a curl or xml2 install failing usually means libcurl-dev or libxml2-dev is missing at the OS level rather than anything wrong in R. On Windows, packages with compiled code need Rtools matched to your R version. In WebR, install.packages() does not apply at all: packages come from the runtime’s own WebAssembly repository, and a package with no wasm build cannot be installed regardless of its CRAN status.

FUNCTIONS WORTH KNOWING

install.packages()installed.packages().libPaths()requireNamespace()BiocManager::install()remotes::install_github()

FREQUENTLY ASKED QUESTIONS

Why do I have to reinstall everything after upgrading R?

R uses a separate library directory per minor version, because compiled packages are built against a specific R ABI. Upgrading 4.3 to 4.4 gives you a fresh empty library. renv or a short reinstall script makes this painless.

What does "package is not available for this version of R" actually mean?

Usually that the package is not on the repository you are querying — it is on Bioconductor or GitHub — rather than that it is incompatible. Occasionally it means the package was archived from CRAN, in which case install from the archive or from GitHub.

Is require() a safe way to check whether a package is installed?

requireNamespace("pkg", quietly = TRUE) is the right test — it returns TRUE or FALSE without attaching. require() also returns a value but attaches the package as a side effect, and library() is the right call once you know it is there.

Still stuck?

Paste your code in RChat and the AI will fix this error in context.

Try RChat Free →

RELATED R ERRORS