Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: renv::snapshot(minimal = TRUE) to generate a slimmed-down renv.lock #2088

Open
fzenoni opened this issue Feb 5, 2025 · 3 comments

Comments

@fzenoni
Copy link

fzenoni commented Feb 5, 2025

Currently, renv.lock files can become bloated because they store all dependencies, metadata, and sources. A minimal lockfile containing only package names and versions would be useful, especially for Docker-based deployments or lightweight version control.

Could an option to renv::snapshot(), such as:

renv::snapshot(minimal = TRUE)

be added, which would generate a lighter renv.lock file with only explicitly used packages and their versions, without extra metadata?

The output could be for example:

{
  "R": {
    "Version": "4.2.1"
  },
  "Packages": {
    "shiny": {
      "Version": "1.7.3"
    },
    "ggplot2": {
      "Version": "3.4.1"
    },
    "dplyr": {
      "Version": "1.1.2"
    }
  }
}

Obtaining such an output currently requires a custom script like:

generate_minimal_lockfile <- function(input_lockfile = "renv.lock", output_file = "renv_minimal.lock") {
  library(jsonlite)
  lock_data <- fromJSON(input_lockfile, simplifyVector = FALSE)
  minimal_lock <- list(R = list(Version = lock_data$R$Version), Packages = lapply(lock_data$Packages, function(pkg) list(Version = pkg$Version)))
  writeLines(toJSON(minimal_lock, pretty = TRUE, auto_unbox = TRUE), output_file)
}
generate_minimal_lockfile()

Thanks for considering it.

@kevinushey
Copy link
Collaborator

Is there a specific motivation for wanting a more minimal lockfile? See also from NEWS:

* `renv` now includes additional package DESCRIPTION fields in the lockfile.
  This can be useful for validating the provenance of packages recorded in the
  lockfile, and also for applications using `renv` which would like to
  recompute the hash used for package caching from the lockfile itself.

  If needed, old-style lockfiles can be generated by setting the option
  `options(renv.lockfile.version = 1)`. Note that this version of `renv`
  remains compatible both with the older (minimal) lockfiles, as well
  as with the newer lockfiles in this release. (#2057)

@fzenoni
Copy link
Author

fzenoni commented Feb 6, 2025

Hi @kevinushey, thank you for your answer.

There is no specific motivation, other than the will to generate a file closer to something like requirements.txt from Python. Your suggestion answers my question.

@jkylearmstrong

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants