lmu-osc / introduction-to-renv

Walkthrough tutorial on setting up and using renv
https://lmu-osc.github.io/introduction-to-renv/
Creative Commons Attribution Share Alike 4.0 International
1 stars 0 forks source link

trouble with restore() that might be relevant for the tutorial #6

Open FlorianPargent opened 6 months ago

FlorianPargent commented 6 months ago

Ironically, I ran into a problem with restoring the packages from the lockfile from this very repo and I think finding a solution how to solve this might be relevant for the tutorial itself.

Problem description: When I renv::restore(), the process aborts because the openssl package cannot be installed. I do not understand why (perhaps because I am on R version 4.4.0).

Failed solutions: I tried installing the newest version of openssl manually with renv::install("openssl") which works. But now, I cannot find any solution how to restore() without installing openssl in the old version again. I have tried using renv::restore(exclude = "openssl") which does not work because openssl is a dependency of several packages. I have tried excluding all packages for which the lockfile lists openssl as a dependency: renv::restore(exclude = c("credentials", "gert", "httr", "httr2", "openssl")) However for reasons that I do not understand, this will still try to install openssl and fails. I have also tried to set options(renv.config.install.transactional = FALSE), because I thought this would allow the restore to keep going even if some packages cannot be installed, but this also does not work.

Do you know how to solve my problem?

FlorianPargent commented 6 months ago

Ok I found a solution, but I do not know whether this is the most elegant one:

  1. I install the newest version from the package that did not work, in my case renv::install("openssl").
  2. I check the version of the newly installed package and overwrite its entry in the lockfile, in my case renv::record("openssl@2.20")
  3. I try renv::restore() again and repeat steps 1 and 2 for all packages that also cannot be installed (which were several in my case)
  4. Assuming it would be my own project where nobody else relies on the current version of the lockfile, I would then run renv::update() to update all packages that are required by the project to the most current version. Then I would use renv::snapshot() to update the lockfile.

What would be much more convenient would be an option that would run renv::update() but not for the packages that are already installed in my project but for all the packages that are recorded in the initial lockfile. Does something like this exist?

FlorianPargent commented 6 months ago

I did not find an option in renv::update() where I can provide a lockfile, there is only the packages argument. One hack that should work is running renv::update(packages = renv::lockfile_read()$Packages |> names()). I cannot believe this functionality is not already available somewhere in renv...

FlorianPargent commented 6 months ago

I think I was wrong and renv::update(packages = renv::lockfile_read()$Packages |> names()) does not work for packages that are not already installed... Maybe one could use renv::install(packages = renv::lockfile_read()$Packages |> names()) instead.

NeuroShepherd commented 6 months ago

Hey Florian, didn't notice you had opened this issue until Malika pointed it out to me yesterday.

In short, I encountered this same problem as you with restoring the library after I updated to R version 4.4.0, and likewise had to tediously install new package versions and record() them in the lockfile. I don't know if there's an explicit fix here, or if there are just cross-version compatibility problems with openssl and R. (Note: I also encounter similar issues somewhat frequently with the MASS and Matrix packages being used with different R versions.)

Some of the Library Management functions might be of use? But I can't be sure without really isolating the problem.

NeuroShepherd commented 5 months ago

@FlorianPargent so I installed rig to play around with restoring {renv} libraries from different versions of R because I've also been constantly running into these installation/restore issues since upgrading to R4.4. Here's what I did:

  1. Started a new RProject under R4.2.3. and created an R script with the following code
    library(MASS)
    library(Matrix)
    library(plotly)
  2. Initialized a renv environment and took a snapshot
  3. Upgraded to R4.3.3 using rig, and attempted to restore the library. Failure on some of the base R packages (lattice, MASS, Matrix), and notes about gcc-8 command not being found.
  4. Upgraded to R4.4.0 using rig, and encountered essentially the same problem as in 3.

At least on my Mac, it seems there's an incompatibility issue with GCC between some of the more recent R versions? In any case, this is something I'll also note in the tutorial and I'll probably make a separate tutorial about using rig.

(Less rigorously, I started a renv project at R4.3.3 and tried to upgrade/downgrade R versions before restoring. Also encountered package installation failures this way.)