rstudio / renv

renv: Project environments for R.
https://rstudio.github.io/renv/
MIT License
971 stars 152 forks source link

`ppm.enabled` in settings vs. config #1901

Open bzkrouse opened 2 weeks ago

bzkrouse commented 2 weeks ago

The documentation implies that the config and settings ppm.enabled options operate similarly. However a recent use case brought up some questions about the difference between these two options. Here is the scenario:

For example, from R 4.3.2, the following code:

renv::install("dplyr", repos = "https://packagemanager.posit.co/cran/2023-03-01")

Results in

# Downloading packages -------------------------------------------------------
- Downloading dplyr from P3M ...                OK [1.5 Mb in 2.1s]
Successfully downloaded 1 package in 2.3 seconds.
The following package(s) will be installed:
- dplyr [1.1.4]

As opposed to downloading dplyr 1.1.0 from the 2023-03-01 snapshot. I have found that if I set config ppm.enabled = FALSE and settings ppm.enabled = TRUE, I think I am able to avoid {renv} from reaching out to P3M, while keeping other benefits of PPM being enabled.

Is this the expected behavior/the recommended configuration for sticking to just the specified repos? If so, is there a way to update the documentation so these 2 options can be more easily distinguished?

Thanks very much in advance for your help!

kevinushey commented 2 weeks ago

Thanks! This seems unexpected to me; I'll need to investigate further.

At least locally, I see:

> renv::install("dplyr", repos = "https://packagemanager.posit.co/cran/2023-03-01")
The following package(s) will be installed:
- dplyr [1.1.0]
These packages will be installed into "~/Library/R/arm64/4.4/library".

Can you share the output of renv::diagnostics(), just in case anything useful is provided therein?

bzkrouse commented 2 weeks ago

@kevinushey thanks for your reply. I should mention I only have this issue on Windows. Here are some diagnostics:


 Diagnostics Report [renv 1.0.7]
===============================

# Session Info ---------------------------------------------------------------
R version 4.3.2 (2023-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8 
[2] LC_CTYPE=English_United States.utf8   
[3] LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.utf8    

time zone: America/New_York
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     
loaded via a namespace (and not attached):
[1] compiler_4.3.2 tools_4.3.2    renv_1.0.7    
# Project --------------------------------------------------------------------
Project path: "~/renv_ppm"

# Status ---------------------------------------------------------------------
This project does not contain a lockfile.
Use `renv::snapshot()` to create a lockfile.
# Packages -------------------------------------------------------------------
This project has not yet been snapshotted: 'renv.lock' does not exist.
            Library Source Lockfile Source Path Dependency
KernSmooth  2.23-22   CRAN     <NA>   <NA>  [2]       <NA>
MASS         7.3-60   CRAN     <NA>   <NA>  [2]       <NA>
Matrix      1.6-1.1   CRAN     <NA>   <NA>  [2]       <NA>
boot       1.3-28.1   CRAN     <NA>   <NA>  [2]       <NA>
class        7.3-22   CRAN     <NA>   <NA>  [2]       <NA>
cluster       2.1.4   CRAN     <NA>   <NA>  [2]       <NA>
codetools    0.2-19   CRAN     <NA>   <NA>  [2]       <NA>
foreign      0.8-85   CRAN     <NA>   <NA>  [2]       <NA>
lattice      0.21-9   CRAN     <NA>   <NA>  [2]       <NA>
mgcv          1.9-0   CRAN     <NA>   <NA>  [2]       <NA>
nlme        3.1-163   CRAN     <NA>   <NA>  [2]       <NA>
nnet         7.3-19   CRAN     <NA>   <NA>  [2]       <NA>
renv          1.0.7   CRAN     <NA>   <NA>  [1]     direct
rpart        4.1.21   CRAN     <NA>   <NA>  [2]       <NA>
spatial      7.3-17   CRAN     <NA>   <NA>  [2]       <NA>
utils          <NA>   <NA>     <NA>   <NA>  [2]   indirect

# ABI ------------------------------------------------------------------------
- ABI conflict checks are not available on Windows.
# User Profile ---------------------------------------------------------------
[no user profile detected]
# Settings -------------------------------------------------------------------
List of 13
 $ bioconductor.version     : NULL
 $ external.libraries       : chr(0) 
 $ ignored.packages         : chr(0) 
 $ package.dependency.fields: chr [1:3] "Imports" "Depends" "LinkingTo"
 $ ppm.enabled              : NULL
 $ ppm.ignored.urls         : chr(0) 
 $ r.version                : NULL
 $ snapshot.type            : chr "implicit"
 $ use.cache                : logi TRUE
 $ vcs.ignore.cellar        : logi TRUE
 $ vcs.ignore.library       : logi TRUE
 $ vcs.ignore.local         : logi TRUE
 $ vcs.manage.ignores       : logi TRUE
# Options --------------------------------------------------------------------
List of 7
 $ defaultPackages                     : chr [1:6] "datasets" "utils" "grDevices" "graphics" ...
 $ download.file.method                : chr "libcurl"
 $ download.file.extra                 : NULL
 $ install.packages.compile.from.source: chr "interactive"
 $ pkgType                             : chr "both"
 $ repos                               : Named chr "https://packagemanager.posit.co/cran/2023-03-01"
  ..- attr(*, "names")= chr "CRAN"
 $ renv.verbose                        : logi TRUE
kevinushey commented 2 weeks ago

Thanks! I can confirm the issue now. The issue is alleviated if you set:

options(renv.config.ppm.enabled = FALSE)

before installation.

The problem occurs because renv looks for the latest-available package either from the current snapshot, or from any other available PPM snapshot, as in here:

https://github.com/rstudio/renv/blob/5d0d52c395e569f7f24df4288d949cef95efca4e/R/available-packages.R#L390-L394

I think if we're already installing from, or using, a specific PPM snapshot, then we'd want to avoid using other PPM snapshots.