rstudio / packrat

Packrat is a dependency management system for R
http://rstudio.github.io/packrat/
401 stars 89 forks source link

ignore packages when recursively enumerating dependencies #654

Closed aronatkins closed 2 years ago

aronatkins commented 2 years ago

previously, we ignored only direct dependencies

Given a Shiny application having:

library(shiny)
library(emo) # hadley/emo

ui <- fluidPage("So much", emo::ji("dancing"))
server <- function(input, output) {}
shinyApp(ui = ui, server = server)

The default set of dependencies:

> packrat:::appDependencies(".")
 [1] "R6"          "Rcpp"        "assertthat"  "base64enc"   "bslib"       "cachem"      "commonmark" 
 [8] "crayon"      "digest"      "ellipsis"    "emo"         "fastmap"     "fontawesome" "fs"         
[15] "generics"    "glue"        "htmltools"   "httpuv"      "jquerylib"   "jsonlite"    "later"      
[22] "lifecycle"   "lubridate"   "magrittr"    "mime"        "packrat"     "promises"    "purrr"      
[29] "rappdirs"    "rlang"       "sass"        "shiny"       "sourcetools" "stringi"     "stringr"    
[36] "withr"       "xtable"     

Prior to this change, with "emo" and "Rcpp" as ignores, only the top-level "emo" is ignored:

> packrat::set_opts(ignored.packages = c("emo","Rcpp"), persist = FALSE)
> packrat:::appDependencies(".")
 [1] "R6"          "Rcpp"        "base64enc"   "bslib"       "cachem"      "commonmark"  "crayon"     
 [8] "digest"      "ellipsis"    "fastmap"     "fontawesome" "fs"          "glue"        "htmltools"  
[15] "httpuv"      "jquerylib"   "jsonlite"    "later"       "lifecycle"   "magrittr"    "mime"       
[22] "packrat"     "promises"    "rappdirs"    "rlang"       "sass"        "shiny"       "sourcetools"
[29] "withr"       "xtable"     

After this change, both "emo" and "Rcpp" are ignored:

> packrat::set_opts(ignored.packages = c("emo","Rcpp"), persist = FALSE)
> packrat:::appDependencies(".")
 [1] "R6"          "base64enc"   "bslib"       "cachem"      "commonmark"  "crayon"      "digest"     
 [8] "ellipsis"    "fastmap"     "fontawesome" "fs"          "glue"        "htmltools"   "httpuv"     
[15] "jquerylib"   "jsonlite"    "later"       "lifecycle"   "magrittr"    "mime"        "packrat"    
[22] "promises"    "rappdirs"    "rlang"       "sass"        "shiny"       "sourcetools" "withr"      
[29] "xtable"     

If we were to choose a dependency with substantial dependencies, we'll see those dependencies disappear, as well; notice that "stringi" is not included as a result of ignoring "stringr"; neither of these are direct project dependencies:

> packrat::set_opts(ignored.packages = c("stringr"), persist = FALSE)
> packrat:::appDependencies(".")
 [1] "R6"          "Rcpp"        "assertthat"  "base64enc"   "bslib"       "cachem"      "commonmark" 
 [8] "crayon"      "digest"      "ellipsis"    "emo"         "fastmap"     "fontawesome" "fs"         
[15] "generics"    "glue"        "htmltools"   "httpuv"      "jquerylib"   "jsonlite"    "later"      
[22] "lifecycle"   "lubridate"   "magrittr"    "mime"        "packrat"     "promises"    "purrr"      
[29] "rappdirs"    "rlang"       "sass"        "shiny"       "sourcetools" "withr"       "xtable"     
toph-allen commented 2 years ago

What I did

I smoke tested this and #656 in a merged branch.

I tested the changes by:

Results

In both cases, all expected packages were ignored. I didn't find any other issues using basic Packrat functions related to these changes.

Running packrat::snapshot(), I got an error Error: Unable to retrieve package records for the following packages: - 'packrat', which I'm assuming is due to packrat being listed in external.packages and/or being built from a local branch.

aronatkins commented 2 years ago

@toph-allen - I think you're right about the packrat dependency. The .snapshotImpl function accepts an implicit.packrat.dependency argument to drop the packrat dependency, but I don't know how best to avoid the snapshot error with a local packrat build. @kevinushey - any testing advice on this?

kevinushey commented 2 years ago

For Packrat's own tests, we use a dummy repository with a mock version of packrat available:

https://github.com/rstudio/packrat/blob/25302c0a63e3e60be0004383dbc2b5f7e1ce84fa/R/testthat-helpers.R#L43-L48

Could something similar be done for testing here? You could also try appending

Repository: CRAN

to the DESCRIPTION file of the external copy of packrat as well, to convince packrat that packrat is available on a CRAN-like repository.

If not, it might suffice to just add some code to packrat to check whether tests are running, and allow for packrat to be missing while running tests.