R "renv" lockfile out of sync in CI
renv compared the project library against renv.lock and they differ. Packages recorded in the lockfile are missing or at a different version, so renv reports the project as out of sync and asks you to restore or snapshot.
What this error means
A renv-based job warns "The project is out-of-sync. Use renv::status() for details." or restore reports packages not installed, and downstream library() calls then fail.
* The project is out-of-sync -- use `renv::status()` for details.
The following package(s) are recorded in the lockfile but not installed:
- jsonlite [1.8.8]Common causes
The library was never restored from the lock
CI ran without renv::restore(), so the project library does not contain the packages and versions the lockfile records.
The lockfile drifted from the code
A package was added or upgraded in code without renv::snapshot(), so the recorded lock no longer matches what the project uses.
How to fix it
Restore the recorded library
- Run
renv::restore()early in the job to install exactly what the lockfile records. - Cache the renv library so restores are fast.
- Re-run so the project library matches the lock.
Rscript -e 'renv::restore()'Snapshot to update a drifted lockfile
If the code legitimately changed dependencies, snapshot and commit the updated lock so CI restores the right set.
Rscript -e 'renv::snapshot()'How to prevent it
- Run
renv::restore()as a dedicated CI step. - Snapshot and commit
renv.lockwhen dependencies change. - Cache the renv package library between runs.