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: add upgrade parameter to renv::install() #1871

Open
jabenninghoff opened this issue Apr 8, 2024 · 5 comments
Open

Feature request: add upgrade parameter to renv::install() #1871

jabenninghoff opened this issue Apr 8, 2024 · 5 comments
Labels
bug an unexpected problem or unintended behavior install 🧺
Milestone

Comments

@jabenninghoff
Copy link

Currently renv::install() always installs the latest version of dependencies. Sometimes it is desirable to install packages without upgrading installed dependencies, like remotes::install_cran("renv", upgrade = "never").

Can an upgrade parameter be added to renv::install() so that it functions like remotes::install_*?

@kevinushey
Copy link
Collaborator

Thanks! Can you provide a concrete example? renv should only attempt to update dependencies if it appears to be necessary. For example, using highr + knitr as an example:

> renv::install("highr")
The following package(s) will be installed:
- highr [0.10]
- xfun  [0.43]
These packages will be installed into "/private/var/folders/9n/3nxsgkrj0rlfx196kzdttpww0000gn/T/tmp.MOEqg19HkM/renv/library/R-4.3/aarch64-apple-darwin20".

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

# Installing packages --------------------------------------------------------
- Installing xfun ...                           OK [linked from cache]
- Installing highr ...                          OK [linked from cache]
Successfully installed 2 packages in 41 milliseconds.

Then, if I downgrade xfun and reinstall highr...

> renv::install("xfun@0.42")
The following package(s) will be installed:
- xfun [0.42]
These packages will be installed into "/private/var/folders/9n/3nxsgkrj0rlfx196kzdttpww0000gn/T/tmp.MOEqg19HkM/renv/library/R-4.3/aarch64-apple-darwin20".

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

# Installing packages --------------------------------------------------------
- Installing xfun ...                           OK [linked from cache]
Successfully installed 1 package in 25 milliseconds.
> remove.packages("highr")
- Removing package(s) from project library ...
Removing package 'highr' ... Done!
> renv::install("highr")
The following package(s) will be installed:
- highr [0.10]
These packages will be installed into "/private/var/folders/9n/3nxsgkrj0rlfx196kzdttpww0000gn/T/tmp.MOEqg19HkM/renv/library/R-4.3/aarch64-apple-darwin20".

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

# Installing packages --------------------------------------------------------
- Installing highr ...                          OK [linked from cache]
Successfully installed 1 package in 13 milliseconds.

Note that xfun was not updated; we still have the older version installed.

> packageVersion("xfun")
[1] ‘0.42’

@jabenninghoff
Copy link
Author

jabenninghoff commented Apr 13, 2024

Sure, there are a couple of examples. From R bug 18396, running install.packages() on macOS is will only install binaries, even when there is a newer source version available. As of today (2024-04-13), the current version of knitr is 1.46, but mac binaries are for 1.45. So, I want to use knitr 1.45 instead of 1.46 until the new binary is available from CRAN.

Unlike for xfun, installing lintr which depends on knitr (no specific version), always upgrades knitr:

> renv::install("knitr@1.45", rebuild = TRUE)
# Downloading packages -------------------------------------------------------
- Downloading knitr from Repository ...         OK [file is up to date]
Successfully downloaded 1 package in 0.35 seconds.

The following package(s) will be installed:
- knitr [1.45]
These packages will be installed into "~/Library/Caches/org.R-project.R/R/renv/library/rdev-7b1a6c08/R-4.3/aarch64-apple-darwin20".

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

# Installing packages --------------------------------------------------------
- Installing knitr ...                          OK [installed binary and cached in 0.32s]
Successfully installed 1 package in 0.35 seconds.
> renv::install("lintr", rebuild = TRUE)
# Downloading packages -------------------------------------------------------
- Downloading lintr from CRAN ...               OK [file is up to date]
Successfully downloaded 1 package in 0.23 seconds.

The following package(s) will be installed:
- knitr [1.46]
- lintr [3.1.2]
These packages will be installed into "~/Library/Caches/org.R-project.R/R/renv/library/rdev-7b1a6c08/R-4.3/aarch64-apple-darwin20".

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

# Installing packages --------------------------------------------------------
- Installing knitr ...                          OK [linked from cache]
- Installing lintr ...                          OK [installed binary and cached in 0.23s]
Successfully installed 2 packages in 0.25 seconds.

The following loaded package(s) have been updated:
- knitr
Restart your R session to use the new versions.

Additionally, after installing the newer development (GitHub) version of a package, renv::install() will install the latest version from CRAN, effectively "downgrading" the package:

> renv::install("yihui/knitr")
# Downloading packages -------------------------------------------------------
- Downloading knitr from GitHub ...             OK [335 Kb in 1.2s]
Successfully downloaded 1 package in 1.2 seconds.

The following package(s) will be installed:
- knitr [yihui/knitr]
These packages will be installed into "~/Library/Caches/org.R-project.R/R/renv/library/rdev-7b1a6c08/R-4.3/aarch64-apple-darwin20".

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

# Installing packages --------------------------------------------------------
- Installing knitr ...                          OK [built from source and cached in 2.6s]
Successfully installed 1 package in 2.6 seconds.

The following loaded package(s) have been updated:
- knitr
Restart your R session to use the new versions.

> renv::install("lintr")
The following package(s) will be installed:
- knitr [1.46]
- lintr [3.1.2]
These packages will be installed into "~/Library/Caches/org.R-project.R/R/renv/library/rdev-7b1a6c08/R-4.3/aarch64-apple-darwin20".

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

# Installing packages --------------------------------------------------------
- Installing knitr ...                          OK [linked from cache]
- Installing lintr ...                          OK [linked from cache]
Successfully installed 2 packages in 20 milliseconds.

The following loaded package(s) have been updated:
- knitr
Restart your R session to use the new versions.

Running renv::snapshot() to record the installed version of knitr doesn't prevent the "downgrade" when running renv::install().

@kevinushey
Copy link
Collaborator

I'm still not able to reproduce.

> renv::install("yihui/knitr")
# Downloading packages -------------------------------------------------------
- Downloading knitr from GitHub ...             OK [335 Kb in 0.65s]
Successfully downloaded 1 package in 0.75 seconds.

The following package(s) will be installed:
- knitr [yihui/knitr]
These packages will be installed into "~/scratch/example/renv/library/R-4.3/aarch64-apple-darwin20".

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

# Installing packages --------------------------------------------------------
- Installing knitr ...                          OK [built from source and cached in 3.7s]
Successfully installed 1 package in 3.7 seconds.
> renv::install("lintr", rebuild = TRUE)
# Downloading packages -------------------------------------------------------
- Downloading lintr from CRAN ...               OK [file is up to date]
Successfully downloaded 1 package in 0.18 seconds.

The following package(s) will be installed:
- lintr [3.1.2]
These packages will be installed into "~/scratch/example/renv/library/R-4.3/aarch64-apple-darwin20".

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

There must be something differentiating my environment from yours, but I'm not sure what it might be.

@jabenninghoff
Copy link
Author

Thanks for checking, I think I found the issue. I created a reproducible example by:

  1. Creating an new R package project in RStudio, "renvtest", selecting "Create a git repository" and "Use renv with this project"
  2. Adding the following lines to DESCRIPTION:
Imports:
    lintr
Suggests:
    knitr
  1. Running the following commands:
renv::install()
renv::install("knitr@1.45")

Then I get the unexpected behavior:

> renv::install("lintr")
The following package(s) will be installed:
- knitr [1.46]
- lintr [3.1.2]
These packages will be installed into "~/Library/Caches/org.R-project.R/R/renv/library/renvtest-9804e798/R-4.3/aarch64-apple-darwin20".

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

- Operation canceled.

> renv::install("yihui/knitr", rebuild = TRUE)
# Downloading packages -------------------------------------------------------
- Downloading knitr from GitHub ...             OK [335 Kb in 0.46s]
Successfully downloaded 1 package in 0.94 seconds.

The following package(s) will be installed:
- knitr [yihui/knitr]
These packages will be installed into "~/Library/Caches/org.R-project.R/R/renv/library/renvtest-9804e798/R-4.3/aarch64-apple-darwin20".

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

# Installing packages --------------------------------------------------------
- Installing knitr ...                          OK [built from source and cached in 2.6s]
Successfully installed 1 package in 2.7 seconds.

> renv::install("lintr")
The following package(s) will be installed:
- knitr [1.46]
- lintr [3.1.2]
These packages will be installed into "~/Library/Caches/org.R-project.R/R/renv/library/renvtest-9804e798/R-4.3/aarch64-apple-darwin20".

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

- Operation canceled.

@kevinushey
Copy link
Collaborator

Thanks! I can reproduce with this example; I appreciate your persistence.

@kevinushey kevinushey added bug an unexpected problem or unintended behavior install 🧺 labels Apr 17, 2024
@kevinushey kevinushey added this to the 1.1.0 milestone Apr 17, 2024
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 install 🧺
Projects
None yet
Development

No branches or pull requests

2 participants