rstudio / packrat

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

Bug: error if requireNamespace is used in function #602

Closed lz100 closed 3 years ago

lz100 commented 4 years ago

I am been redirected from the rsconnect issue to here.

First, if I have code like this in my function, packrat treat the variable pkg as a real package name.

missing_pkgs <- lapply(packages, function(pkg) {
        if (!requireNamespace(pkg, quietly = TRUE)) pkg
})

Second, this code is used for checking the user environment, I don't want to install or attach the package, so that's why I use requireNamespace instead of require. packrat also thinks anything in requireNamespace is needed, but they are not.

if you run packrat:::appDependencies():

Warning message:
In FUN(X[[i]], ...) : Package 'pkg' not available in repository or locally

This is a warning here, but will become an error in rsconnect and prevent my deployment.

Is there an official way to fix this instead of my hack?

Thanks!

aronatkins commented 3 years ago
> packrat:::fileDependencies.R("app.R")
[1] "shiny" "pkg"  

The lower-level logic for handling an expression: https://github.com/rstudio/packrat/blob/84cbc96726a380dfbdf601535695554241b2acb6/R/dependencies.R#L400-L464