precommit
precommit copied to clipboard
New hook: renv hook
Check if the renv.lock is up to date by running renv::status(). This is potentially expensive.
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?
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()."
)
Thanks!
You could even do the R code inline in .pre-commit-config.yaml, then you don't need bin/renv.R.
entry: Rscript -e '...'
Is there a way to do it without the dep on assertthat? @lorenzwalthert @fh-mthomson
Well just use stop()?