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

renv::status() doesn't warn of wrong R version #1779

Closed
eliocamp opened this issue Dec 15, 2023 · 4 comments
Closed

renv::status() doesn't warn of wrong R version #1779

eliocamp opened this issue Dec 15, 2023 · 4 comments
Labels
bug an unexpected problem or unintended behavior status 🔮
Milestone

Comments

@eliocamp
Copy link

Running renv::status() doesn't warn if the R version being used is not the same as the one recorded in the lockfile. Example lockfile:

{
  "R": {
    "Version": "4.2.3",
    "Repositories": [
      {
        "Name": "CRAN",
        "URL": "https://packagemanager.posit.co/cran/latest"
      }
    ]
  },
  "Packages": {
    "renv": {
      "Package": "renv",
      "Version": "1.0.3",
      "Source": "Repository",
      "Repository": "RSPM",
      "Requirements": [
        "utils"
      ],
      "Hash": "41b847654f567341725473431dd0d5ab"
    }
  }
}

If I open this project with R 4.3.1, renv::status() reports "no issues found". The only indication that I'm not using the correct R version is a message at startup (ℹ Using R 4.3.1 (lockfile was generated with R 4.2.3)) which gets lost among the usual R startup nonsense.

@kevinushey kevinushey added bug an unexpected problem or unintended behavior status 🔮 labels Dec 16, 2023
@kevinushey kevinushey added this to the 1.1.0 milestone Dec 16, 2023
@jkylearmstrong
Copy link

I came here to report similar issue, I was surprised that there isn't a warning about the R version difference, and that the lockfile will happily just change the version in the lockfile:

> renv::restore()
The version of R recorded in the lockfile will be updated:
- R   [4.3.2 -> 4.3.1]

I don't think this behavior is expected.

@kevinushey
Copy link
Collaborator

I don't think this behavior is expected.

Why not? When you call renv::snapshot(), the version of R that is currently in use is used when updating the lockfile. If you want to 'freeze' the version of R used independently, you can use the r.version project option: https://rstudio.github.io/renv/reference/settings.html#r-version

@mfebrizio
Copy link

mfebrizio commented Dec 22, 2023

I agree that adding a warning to renv::status() would be useful, as @eliocamp suggested. We had this need for another project and addressed it by adding some code to .Rprofile (after referencing this stackoverflow post). Hope it's okay to share here for those looking for a temporary fix.

# prints warning if system version of R differs from renv project
r_version <- renv::lockfile_read()$R$Version
if (paste0(version$major, ".", version$minor) != (r_version)) {
  warning(paste0("R version ", version$major, ".", version$minor, " is in use. R version ", r_version, " is required."))
}

@jkylearmstrong
Copy link

It took me a couple of instances of going between my two machines. I would snapshot on one, then back up to git, download on the other, then hydrate / restore from the lock file... I would have thought that I would have gotten a notice that I was restoring from a different version of R.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior status 🔮
Projects
None yet
Development

No branches or pull requests

4 participants