precommit icon indicating copy to clipboard operation
precommit copied to clipboard

New hook: renv hook

Open lorenzwalthert opened this issue 4 years ago • 6 comments
trafficstars

Check if the renv.lock is up to date by running renv::status(). This is potentially expensive.

lorenzwalthert avatar Mar 03 '21 15:03 lorenzwalthert

Any potential for this to be implemented in the near future? I think potentially even just running renv::snapshot(prompt = FALSE) might be sufficient on a certain set of files?

HarrisonWilde avatar Jun 09 '25 18:06 HarrisonWilde

If it's helpful, here's a minimal version we've implemented manually:

.pre-commit-config.yaml:

repos:
-   repo: local
    hooks:
    - id: renv
      name: renv
      entry: bin/renv.R
      language: script
      files: '\.[rR](md)?$'

bin/renv.R:

#!/usr/bin/env Rscript
renv_status <- renv::status()

assertthat::assert_that(
  renv_status$synchronized,
  msg = "Environment is not in sync with renv.lock file. See above results of renv::status()."
)

fh-mthomson avatar Jun 09 '25 18:06 fh-mthomson

Thanks!

HarrisonWilde avatar Jun 09 '25 19:06 HarrisonWilde

You could even do the R code inline in .pre-commit-config.yaml, then you don't need bin/renv.R.

entry: Rscript -e '...'

lorenzwalthert avatar Jun 09 '25 19:06 lorenzwalthert

Is there a way to do it without the dep on assertthat? @lorenzwalthert @fh-mthomson

HarrisonWilde avatar Jun 09 '25 21:06 HarrisonWilde

Well just use stop()?

lorenzwalthert avatar Jun 09 '25 21:06 lorenzwalthert