Skip to content

Packages are not found after R upgrade

Lorenz Walthert edited this page May 19, 2024 · 11 revisions

Here is what you may see

For example if you see

Error in loadNamespace(x) : there is no package called ‘docopt’
Calls: loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart
Execution halted

After an R minor or major upgrade, pre-commit may wants to use old and incompatible binaries / installed packages.

What you need to do

You need to destroy the invalid links and let pre-commit link these again with the correct version.

  • run pre-commit clean to delete the pre-commit cache.
  • run pre-commit install --install-hooks
  • try to commit again.
  • if it fails, remove offending package with version from {renv} cache. E.g. for the above, run renv::purge('docopt') (does not matter from which working directory and if a renv is activated) and confirm the prompt. You may later have to do that again if other packages are not found. Then, install the package manually with renv (so it's added to the cache) with renv::install('docopt').
  • try to commit again.