rstudio / renv

renv: Project environments for R.
https://rstudio.github.io/renv/
MIT License
1.02k stars 155 forks source link

`upgrade` doesn't update `activate.R` in 1.0.5 #1837

Open hutch3232 opened 7 months ago

hutch3232 commented 7 months ago

Hi @kevinushey, thanks as always for the amazing renv package! I tried using renv::upgrade to go from 1.0.4 to 1.0.5 this morning and encountered this issue:

# no renv.lock

> renv::upgrade()
A new version of the renv package will be installed:

# CRAN -----------------------------------------------------------------------
- renv   [* -> 1.0.5]

This project will use the newly-installed version of renv.

Do you want to proceed? [Y/n]: y

# Installing packages --------------------------------------------------------
- Installing renv ...                           OK [linked from cache]
- Lockfile written to "/mnt/code/renv.lock".
- Updating activate script

Restarting R session...

renv 1.0.5 was loaded from project library, but this project is configured to use renv 1.0.4.
- Use `renv::record("renv@1.0.5")` to record renv 1.0.5 in the lockfile.
- Use `renv::restore(packages = "renv")` to install renv 1.0.4 into the project library.
- Project '/mnt/code' loaded. [renv 1.0.5]
- The project is out-of-sync -- use `renv::status()` for details.

# with renv.lock and status up to date

> renv::upgrade()
A new version of the renv package will be installed:

# CRAN -----------------------------------------------------------------------
- renv   [1.0.4 -> 1.0.5]

This project will use the newly-installed version of renv.

Do you want to proceed? [Y/n]: y

# Installing packages --------------------------------------------------------
- Installing renv ...                           OK [linked from cache]
- Lockfile written to "/mnt/code/renv.lock".
- Updating activate script

Restarting R session...

# at this point I received this RStudio error/popup/modal
# (Error: Save File) Error occurred during transmission (OK)

renv 1.0.5 was loaded from project library, but this project is configured to use renv 1.0.4.
- Use `renv::record("renv@1.0.5")` to record renv 1.0.5 in the lockfile.
- Use `renv::restore(packages = "renv")` to install renv 1.0.4 into the project library.
- Project '/mnt/code' loaded. [renv 1.0.5]

The fix was very simple. I just ran renv::activate() and it then changed the one line in renv/activate.R to reflect the new version number. Then I ran renv::snapshot() to cleanup the renv record, but this latter behavior is not new to 1.0.5, I've always needed to do that.

kevinushey commented 7 months ago

The activate script should be getting updated here:

https://github.com/rstudio/renv/blob/536e04d2b6e28c613a1a79518ddffb51a1dcde6a/R/upgrade.R#L102-L119

Any chance you're able to do something like:

debug(renv:::r)
renv::upgrade()

and see if you can figure out what's going wrong?

hutch3232 commented 7 months ago

As you can see I turned off the silent flags when running R for debugging purposes.

args <- c("--vanilla", "-f", renv_shell_path(script))
r(args)

R version 4.3.1 (2023-06-16) -- "Beagle Scouts"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> {
+     renv <- asNamespace("renv")
+     renv$summon()
+     NULL <- renv_metadata_version_create(structure(list(Package = "renv",
+         Version = "1.0.5", OS_type = NA_character_, NeedsCompilation = "no",
+         Repository = "CRAN", Source = "Repository"), url = "https://mypackage_repo.com/cran/src/contrib", type = "source", name = "CRAN"))
+     renv_infrastructure_write("/mnt/code", version = NULL)
+ }
Error in NULL <- renv_metadata_version_create(structure(list(Package = "renv",  :
  invalid (do_set) left-hand side to assignment
Execution halted

I think it's because version exists in this scope and is NULL.

kevinushey commented 7 months ago

🤦 You are definitely right. I'll take a look.

kevinushey commented 7 months ago

Should now be resolved with the latest development builds of renv; are you able to confirm?

hutch3232 commented 7 months ago

Thank you for working on this! I attempted to test it. It was a bit less clear how I should do that but here is what I tried.

I found the commit where it looked like you introduced the fix, so I installed that version of renv. Then I ran renv::upgrade in debug mode. Like before, I turned off the silencing of errors and received this:

devtools::install_github(repo = "rstudio/renv", ref = "60a8e4bd484cfded9757780c2edb28aa8a2d68fe")
A new version of the renv package will be installed:

# GitHub ---------------------------------------------------------------------
- renv   [ver: 1.0.5.9000 -> 0.17.3-62; ref: 48a3815d1062d1913c3af361ae1a365090254c92 -> 0.17.3-62; sha: 48a3815d -> bdafa403]

This project will use the newly-installed version of renv.

R version 4.3.3 (2024-02-29 ucrt) -- "Angel Food Cake"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> {
+     renv <- asNamespace("renv")
+     renv$summon()
+     version <- renv_metadata_version_create(list(Package = "renv", 
+         Version = "0.17.3-62", Source = "GitHub", RemoteType = "github", 
+         RemoteHost = "api.github.com", RemoteUsername = "rstudio", 
+         RemoteRepo = "renv", RemoteRef = "0.17.3-62", RemoteSha = "bdafa4033ec3166aa1f36a4f02db8e3d09ca4ae0"))
+     renv_infrastructure_write(project, version = version)
+ }
Error: attempt to apply non-function
Execution halted

It isn't clear to me what has gone wrong but I'm happy to try other testing/troubleshooting steps if you have any you'd like me to try.