rstudio / packrat

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

Tracking dependencies for shinyapps deployment #550

Closed dchiu911 closed 5 years ago

dchiu911 commented 5 years ago

Is there a simple way for packrat to track packages that are needed for deploying to shinyapps? Currently when I run packrat::clean() it (correctly) determines that PKI, RCurl, RJSONIO, and rsconnect are not used in my shiny project. But, they are actually needed at deployment.

dchiu911 commented 5 years ago

I guess these can be treated as feasible false positives

cderv commented 5 years ago

I think it is possible to not include this package into your packrat projet by using them as external packages that are not tracked (as an option or env var, or using packrat::with_extlib() or packrat::extlib() to deploy your project)

I used this mechanism on some projects to deploy some project to Rstudio Connect.

dchiu911 commented 5 years ago

That is true, however I wouldn't be able to use the Publish preview dialog box in RStudio because it prompts me to install packages when I try to click it.

cderv commented 5 years ago

I think if you use the packrat options external.packages inside the packrat.opts file, the packages would be available for your project but not tracked by packrat.

dchiu911 commented 5 years ago

Thanks, that option works! A short note on my workflow. It seems that running packrat::set_opts() immediately after packrat::clean() moves certain packages to the User library without changes detected by packrat.lock.

packrat::clean()
#> The following packages have been removed:
#> - 'fansi', 'PKI', 'RCurl', 'RJSONIO', 'rsconnect'
packrat::set_opts(external.packages = c("PKI", "RCurl", "RJSONIO", "rsconnect"))
packrat::status()
#> The following packages are tracked by packrat, but are no longer available in the local library nor present in your code:
#>           _      
#>     fansi   0.4.0
#> 
#> You can call packrat::snapshot() to remove these packages from the lockfile, or if you intend to use these packages, use packrat::restore() to restore them to your private library.

The correct workflow should be

packrat::clean()
packrat::snapshot()
#> Removing these packages from packrat:
#>               _          
#>     PKI         0.1-5.1  
#>     RCurl       1.95-4.11
#>     RJSONIO     1.3-1.1  
#>     fansi       0.4.0    
#>     rsconnect   0.8.11   
packrat::set_opts(external.packages = c("PKI", "RCurl", "RJSONIO", "rsconnect"))
packrat::status()
#> Up to date.