rstudio / packrat

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

packrat::with_extlib not working with devtools 2.0.1 for install_github #516

Closed czeildi closed 5 years ago

czeildi commented 6 years ago

I cannot install using devtools in a packrat project unless I install devtools within the project which seems unnecessary for running 1 command, install_github.

I am not sure if this is a packrat or pkgload issue:

I ran the following in a completely new project, the only previous command was packrat::init()

packrat::with_extlib(
    "devtools",
    devtools::install_github("r-lib/pkgdown")
)

#> Error: package or namespace load failed for ‘devtools’:
#>     .onLoad failed in loadNamespace() for 'pkgload', details:
#>     call: loadNamespace(name)
#> error: there is no package called ‘withr’

packrat::with_extlib("withr", sessionInfo())

#> R version 3.5.0 (2018-04-23)
#> Platform: x86_64-apple-darwin15.6.0 (64-bit)
#> Running under: macOS Sierra 10.12.6
#> 
#> Matrix products: default
#> BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
#> 
#> locale:
#>     [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#> 
#> attached base packages:
#>     [1] stats     graphics  grDevices utils     datasets  methods  
#> [7] base     
#> 
#> other attached packages:
#>     [1] withr_2.1.2
#> 
#> loaded via a namespace (and not attached):
#>     [1] processx_3.1.0    compiler_3.5.0    magrittr_1.5     
#> [4] R6_2.3.0          assertthat_0.2.0  cli_1.0.1        
#> [7] prettyunits_1.0.2 tools_3.5.0       memoise_1.1.0    
#> [10] crayon_1.3.4      callr_2.0.4       digest_0.6.18    
#> [13] pkgbuild_1.0.2    packrat_0.4.9-3   rlang_0.3.0   

packrat::with_extlib(
    c("devtools", "pkgload", "withr"),
    devtools::install_github("r-lib/pkgdown")
)

#> Error: package or namespace load failed for ‘devtools’:
#>     .onLoad failed in loadNamespace() for 'pkgload', details:
#>     call: loadNamespace(name)
#> error: there is no package called ‘withr’

devtools::install_github works fine after installing devtools within the project.

The above is a manual "reprex" as it seems reprex and packrat does not work well together, with running reprex on the above script, installation worked fine.

packrat::with_extlib(
    c("reprex", "whisker", "callr", "rmarkdown", "clipr"),
    reprex::reprex(input = "reprex.R")
)

I suspect the following part of pkgload is related but I am not sure: https://github.com/r-lib/pkgload/blob/0ef4f58cd8135e9e77c21243e466b9739e608bde/R/zzz.r#L1

Any pointers would be appreciated! thanks


reprex output:

packrat::with_extlib(
    "devtools",
    devtools::install_github("r-lib/pkgdown")
)
#> Skipping install of 'pkgdown' from a github remote, the SHA1 (8f543c2e) has not changed since last install.
#>   Use `force = TRUE` to force installation
#> Warning: 'usethis' namespace cannot be unloaded:
#>   namespace 'usethis' is imported by 'devtools' so cannot be unloaded
#> [1] "pkgdown"

Created on 2018-11-11 by the reprex package (v0.2.0).


reprex output 2:

If I start my code example with packrat::init()

packrat::init()
#> Initializing packrat project in directory:
#> - "/private/var/folders/rw/ky5hq6q95kd66vw7mpbsnx5w0000gp/T/RtmpXvJch5"
#> Unable to tangle file '/private/var/folders/rw/ky5hq6q95kd66vw7mpbsnx5w0000gp/T/RtmpXvJch5/file111cf57660bfe_reprex.spin.Rmd'; cannot parse dependencies
#> Warning in file(con, "r"): cannot open file '/var/folders/rw/
#> ky5hq6q95kd66vw7mpbsnx5w0000gp/T//Rtmp0JodSq/file111ddd7241f0': No such
#> file or directory
#> Error in file(con, "r"): cannot open the connection

packrat::with_extlib(
    "devtools",
    devtools::install_github("r-lib/pkgdown")
)
#> Downloading GitHub repo r-lib/pkgdown@master
#> callr      (2.0.4     -> 3.0.0    ) [CRAN]
#> commonmark (1.5       -> 1.6      ) [CRAN]
#> evaluate   (0.10.1    -> 0.12     ) [CRAN]
#> fansi      (NA        -> 0.4.0    ) [CRAN]
#> highr      (0.6       -> 0.7      ) [CRAN]
#> mime       (0.5       -> 0.6      ) [CRAN]
#> packrat    (0.4.9-2   -> 0.4.9-3  ) [CRAN]
#> pillar     (1.2.3     -> 1.3.0    ) [CRAN]
#> processx   (3.1.0     -> 3.2.0    ) [CRAN]
#> ps         (NA        -> 1.2.1    ) [CRAN]
#> Rcpp       (0.12.19   -> 1.0.0    ) [CRAN]
#> RCurl      (1.95-4.10 -> 1.95-4.11) [CRAN]
#> rlang      (0.3.0     -> 0.3.0.1  ) [CRAN]
#> roxygen2   (6.1.0     -> 6.1.1    ) [CRAN]
#> tinytex    (0.5       -> 0.9      ) [CRAN]
#> xfun       (0.3       -> 0.4      ) [CRAN]
#> Installing 16 packages: callr, commonmark, evaluate, fansi, highr, mime, packrat, pillar, processx, ps, Rcpp, RCurl, rlang, roxygen2, tinytex, xfun
#> 
#> The downloaded binary packages are in
#>  /var/folders/rw/ky5hq6q95kd66vw7mpbsnx5w0000gp/T//Rtmp0JodSq/downloaded_packages
#> Warning in get0(oNam, envir = ns): internal error -3 in R_decompress1
#> Error: lazy-load database '/Library/Frameworks/R.framework/Versions/3.5/Resources/library/callr/R/callr.rdb' is corrupt
#> Warning: 'usethis' namespace cannot be unloaded:
#>   namespace 'usethis' is imported by 'devtools' so cannot be unloaded

#> Error: package or namespace load failed for ‘devtools’:
#>     .onLoad failed in loadNamespace() for 'pkgload', details:
#>     call: loadNamespace(name)
#> error: there is no package called ‘withr’

packrat::with_extlib("withr", sessionInfo())
#> Warning: 'withr' namespace cannot be unloaded:
#>   namespace 'withr' is imported by 'sessioninfo' so cannot be unloaded
#> R version 3.5.0 (2018-04-23)
#> Platform: x86_64-apple-darwin15.6.0 (64-bit)
#> Running under: macOS Sierra 10.12.6
#> 
#> Matrix products: default
#> BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
#> 
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] withr_2.1.2
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_1.0.0         knitr_1.20         magrittr_1.5      
#>  [4] usethis_1.4.0.9000 pkgload_1.0.2      debugme_1.1.0     
#>  [7] R6_2.3.0           rlang_0.3.0.1      stringr_1.3.1     
#> [10] tools_3.5.0        pkgbuild_1.0.2     packrat_0.4.9-3   
#> [13] sessioninfo_1.0.0  cli_1.0.1          remotes_2.0.2     
#> [16] htmltools_0.3.6    yaml_2.2.0         assertthat_0.2.0  
#> [19] rprojroot_1.3-2    digest_0.6.18      crayon_1.3.4      
#> [22] processx_3.2.0     callr_3.0.0        fs_1.2.6          
#> [25] clisymbols_1.2.0   curl_3.2           testthat_2.0.1    
#> [28] glue_1.3.0         memoise_1.1.0      evaluate_0.12     
#> [31] rmarkdown_1.10     stringi_1.2.4      compiler_3.5.0    
#> [34] desc_1.2.0         backports_1.1.2    prettyunits_1.0.2

#> R version 3.5.0 (2018-04-23)
#> Platform: x86_64-apple-darwin15.6.0 (64-bit)
#> Running under: macOS Sierra 10.12.6
#> 
#> Matrix products: default
#> BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
#> 
#> locale:
#>     [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#> 
#> attached base packages:
#>     [1] stats     graphics  grDevices utils     datasets  methods  
#> [7] base     
#> 
#> other attached packages:
#>     [1] withr_2.1.2
#> 
#> loaded via a namespace (and not attached):
#>     [1] processx_3.1.0    compiler_3.5.0    magrittr_1.5     
#> [4] R6_2.3.0          assertthat_0.2.0  cli_1.0.1        
#> [7] prettyunits_1.0.2 tools_3.5.0       memoise_1.1.0    
#> [10] crayon_1.3.4      callr_2.0.4       digest_0.6.18    
#> [13] pkgbuild_1.0.2    packrat_0.4.9-3   rlang_0.3.0   

packrat::with_extlib(
    c("devtools", "pkgload", "withr"),
    devtools::install_github("r-lib/pkgdown")
)
#> Downloading GitHub repo r-lib/pkgdown@master
#> Warning in get0(oNam, envir = ns): restarting interrupted promise
#> evaluation
#> Warning in get0(oNam, envir = ns): internal error -3 in R_decompress1
#> Error: lazy-load database '/Library/Frameworks/R.framework/Versions/3.5/Resources/library/callr/R/callr.rdb' is corrupt
#> Warning: 'withr' namespace cannot be unloaded:
#>   namespace 'withr' is imported by 'sessioninfo', 'devtools' so cannot be unloaded
#> Warning: 'pkgload' namespace cannot be unloaded:
#>   namespace 'pkgload' is imported by 'devtools' so cannot be unloaded
#> Warning: 'usethis' namespace cannot be unloaded:
#>   namespace 'usethis' is imported by 'devtools' so cannot be unloaded

#> Error: package or namespace load failed for ‘devtools’:
#>     .onLoad failed in loadNamespace() for 'pkgload', details:
#>     call: loadNamespace(name)
#> error: there is no package called ‘withr’

Created on 2018-11-11 by the reprex package (v0.2.0).

czeildi commented 6 years ago

Related issue: https://github.com/rstudio/packrat/issues/65

cderv commented 6 years ago

It does not explain the error, but you may have less issues with remotes::install_github because it has less dependencies to other 📦 .

packrat::with_extlib(
    "remotes",
    install_github("r-lib/pkgdown")
)

There seems to be something off with .onLoad call, I have a similar with some simple example.

tempdir <- tempfile()
dir.create(tempdir)
setwd(tempdir)
packrat::init(restart = FALSE)
#> Initializing packrat project in directory:
#> - "C:/Users/chris/AppData/Local/Temp/RtmpkVdJ4G/file11ae01d2d24ac"
#> 
#> Adding these packages to packrat:
#>             _        
#>     packrat   0.4.9-3
#> Fetching sources for packrat (0.4.9-3) ...
#> OK (CRAN current)
#> Snapshot written to "C:/Users/chris/AppData/Local/Temp/RtmpkVdJ4G/file11ae01d2d24ac/packrat/packrat.lock"
#> Installing packrat (0.4.9-3) ...
#>  OK (downloaded binary)
#> Initialization complete!
.libPaths()
#> [1] "C:/Users/chris/AppData/Local/Temp/RtmpkVdJ4G/file11ae01d2d24ac/packrat/lib/x86_64-w64-mingw32/3.5.1"    
#> [2] "C:/Users/chris/AppData/Local/Temp/RtmpkVdJ4G/file11ae01d2d24ac/packrat/lib-ext/x86_64-w64-mingw32/3.5.1"
#> [3] "C:/Users/chris/AppData/Local/Temp/RtmpkVdJ4G/file11ae01d2d24ac/packrat/lib-R/x86_64-w64-mingw32/3.5.1"
devtools::install_github("r-lib/glue")
#> Error in loadNamespace(name): aucun package nommé 'devtools' n'est trouvé
packrat::with_extlib("devtools",
                     install_github("tidyverse/glue")
)
#> Error: package or namespace load failed for 'devtools':
#>  .onLoad a échoué dans loadNamespace() pour 'processx', détails :
#>   appel : loadNamespace(name)
#>   erreur : aucun package nommé 'ps' n'est trouvé
packrat::with_extlib("remotes",
                     install_github("tidyverse/glue")
)
#> Downloading GitHub repo tidyverse/glue@master
#> Running `R CMD build`...
#> * checking for file 'C:\Users\chris\AppData\Local\Temp\RtmpkVdJ4G\remotes11ae05f6662c6\tidyverse-glue-35c61e9/DESCRIPTION' ... OK
#> * preparing 'glue':
#> * checking DESCRIPTION meta-information ... OK
#> * cleaning src
#> * checking for LF line-endings in source and make files and shell scripts
#> * checking for empty or unneeded directories
#> * building 'glue_1.3.0.tar.gz'
#> Installing package into 'C:/Users/chris/AppData/Local/Temp/RtmpkVdJ4G/file11ae01d2d24ac/packrat/lib/x86_64-w64-mingw32/3.5.1'
#> (as 'lib' is unspecified)
#> [1] "glue"

for reprex with packrat, reprex::reprex(advertise = FALSE) can help.

KZARCA commented 6 years ago

I have a similar problem. Actually, I cannot use devtools from inside a project using packrat:

> library(packrat)
> extlib("devtools")
Erreur : package or namespace load failed for ‘devtools’:
 .onLoad failed in loadNamespace() for 'pkgload', details:
  call: loadNamespace(name)
  error: there is no package called ‘desc’

Actually, it only works if I I load devtools dependencies outside my packrat library like this: extlib(c("desc", "usethis", "devtools"))

cderv commented 6 years ago

Due to a change in packrat 0.5.0, the example above are no more working. This one which was working correctly does not anymore because with_extlib changes .libPaths() now.

packrat::with_extlib("remotes",
                     install_github("tidyverse/glue")
)

will install glue but in user libpath, not packrat project libpath.

czeildi commented 5 years ago

Thanks @cderv , indeed the behavior and issues are quite different w packrat 0.5.0 , without you I did not realize there was a new CRAN release of packrat.

I will close this issue as I believe #517 is more focused and up to date.