Skip to content
Latchkey

R "could not find function X" in CI

R evaluated a call to a function name that is not on the search path. The package that exports it was never attached with library(), or the installed version no longer defines that function.

What this error means

A script fails with "Error in ... : could not find function 'X'", typically because the package was installed but not loaded, or a different version is installed in CI.

R
Error in mutate(df, y = x + 1) : could not find function "mutate"
Execution halted

Common causes

The package is installed but not attached

The function exists in a package that was never loaded with library(), so its name is not visible on the search path.

A version mismatch removed or renamed the function

CI resolved a different package version in which the function was renamed, removed, or not yet added.

How to fix it

Attach the package or qualify the call

  1. Load the package with library() before calling its functions.
  2. Or call it fully qualified as pkg::fn().
  3. Re-run to confirm the function resolves.
R
library(dplyr)
# or call it without attaching:
dplyr::mutate(df, y = x + 1)

Pin the package version that defines it

If the function moved between versions, pin a version that still exports it and record it in the lockfile.

Terminal
Rscript -e 'remotes::install_version("dplyr", version="1.1.4")'

How to prevent it

  • Attach every package a script uses, or qualify calls with pkg::.
  • Lock package versions so the exported function set is stable.
  • Re-run installs after version bumps to catch renamed functions.

Frequently asked questions

What causes ""could not find function""?
The function exists in a package that was never loaded with library(), so its name is not visible on the search path.
How do I fix "could not find function"?
Attach the package or qualify the call

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card