rstudio / packrat

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

Error adding packrat to existing project on MacOSX #314

Open alepulver opened 8 years ago

alepulver commented 8 years ago

I get an error when trying to add packrat to my existing project on MacOSX 10.11 and latest R installed from homebrew. The project is available here: https://github.com/alepulver/my-thesis

packrat::init()
Initializing packrat project in directory:
- "~/Google Drive/my-thesis/analysis-in-r"
Error in isNamespaceLoaded(pkg) : 
  attempt to use zero-length variable name
In addition: There were 16 warnings (use warnings() to see them)
> warnings()
Warning messages:
1: In readLines(file) :
  incomplete final line found on '/Users/alejandropulver/Google Drive/my-thesis/analysis-in-r/comparacion_cottle.Rmd'
2: In readLines(file) :
  incomplete final line found on '/Users/alejandropulver/Google Drive/my-thesis/analysis-in-r/exploratorio.Rmd'
3: In readLines(file) :
  incomplete final line found on '/Users/alejandropulver/Google Drive/my-thesis/analysis-in-r/figuras_poster.Rmd'
4: In readLines(file) :
  incomplete final line found on '/Users/alejandropulver/Google Drive/my-thesis/analysis-in-r/fragmentos_no_utilizados.Rmd'
5: In readLines(file) :
  incomplete final line found on '/Users/alejandropulver/Google Drive/my-thesis/analysis-in-r/machine_learning_analisis.Rmd'
6: In readLines(file) :
  incomplete final line found on '/Users/alejandropulver/Google Drive/my-thesis/analysis-in-r/machine_learning_pruebas.Rmd'
7: In readLines(file) :
  incomplete final line found on '/Users/alejandropulver/Google Drive/my-thesis/analysis-in-r/modelos_cottle.Rmd'
8: In readLines(file) :
  incomplete final line found on '/Users/alejandropulver/Google Drive/my-thesis/analysis-in-r/modelos_hipotesis_especificas.Rmd'
9: In value[[3L]](cond) :
  Failed to parse /var/folders/f1/64_sc7dn0_v3vh7gbwrc0vvw0000gp/T//Rtmp0m4P7K/file49307e41f209 ; dependencies in this file will not be discovered.
10: In readLines(file) :
  incomplete final line found on '/Users/alejandropulver/Google Drive/my-thesis/analysis-in-r/modelos_hipotesis_primarias.Rmd'
11: In value[[3L]](cond) :
  Failed to parse /var/folders/f1/64_sc7dn0_v3vh7gbwrc0vvw0000gp/T//Rtmp0m4P7K/file4930410c731e ; dependencies in this file will not be discovered.
12: In readLines(file) :
  incomplete final line found on '/Users/alejandropulver/Google Drive/my-thesis/analysis-in-r/template_colores.Rmd'
13: In readLines(file) :
  incomplete final line found on '/Users/alejandropulver/Google Drive/my-thesis/analysis-in-r/template_cottle.Rmd'
14: In readLines(file) :
  incomplete final line found on '/Users/alejandropulver/Google Drive/my-thesis/analysis-in-r/template_dedicacion.Rmd'
15: In readLines(file) :
  incomplete final line found on '/Users/alejandropulver/Google Drive/my-thesis/analysis-in-r/template_ubicacion_xy.Rmd'
16: In FUN(X[[i]], ...) : Package '' not available in repository or locally
kevinushey commented 8 years ago

Thanks -- the warnings can be ignored, but we should definitely suppress the ones related to readLines + trailing newlines.

kevinushey commented 8 years ago

This bit:

Error in isNamespaceLoaded(pkg) : 
  attempt to use zero-length variable name

looks like an error due to us detecting something like an empty library() call, or something to that effect. I'll take a look!

rtelmore commented 7 years ago

Did anybody happen to find an issue for this:

Error in isNamespaceLoaded(pkg) : 
  attempt to use zero-length variable name
alisol86 commented 7 years ago

I would also like to know if there is any progress on this?

No matter how do I set the options in packrat::init call, I always het the following error:

Error in isNamespaceLoaded(pkg) : attempt to use zero-length variable name In addition: Warning message: In FUN(X[[i]], ...) : Package '' not available in repository or locally

kevinushey commented 7 years ago

If you could provide a reproducible example, that would greatly help us figure out what's going on.

rtelmore commented 7 years ago

I can't. I reinstalled everything...R, RStudio, packrat, packages, etc., and now everything is working. Sorry I can't be of more help.

alisol86 commented 7 years ago

I somehow managed to overcome this problem by reverting back to a former version of the project (although I still don't understand what was the cause of the error).

Now I am getting another error as following for the sp and rgdal packages, looks like has to do with the package dependencies.

packrat::init(options = list(vcs.ignore.src = TRUE))
Initializing packrat project in directory:
- "~/dev/apps_src/KLIP_NDVI_v02"

Adding these packages to packrat:
                    _         
    BH                1.62.0-1
    DBI               0.6     
    DT                0.2     
    MASS              7.3-45  
    R6                2.2.0   
    RColorBrewer      1.1-2   
    Rcpp              0.12.10 
    TeachingDemos     2.10    
    V8                1.5     
    assertthat        0.1     
    base64enc         0.1-3   
    broom             0.4.2   
    codetools         0.2-15  
    colorspace        1.3-2   
    crosstalk         1.0.0   
    curl              2.5     
    dichromat         2.0-0   
    digest            0.6.12  
    dplyr             0.5.0   
    dygraphs          1.1.1.4 
    forcats           0.2.0   
    foreach           1.4.3   
    foreign           0.8-67  
    geojsonio         0.3.2   
    ggplot2           2.2.1   
    ggvis             0.4.3   
    gridExtra         2.2.1   
    gtable            0.2.0   
    haven             1.0.0   
    hms               0.3     
    htmltools         0.3.5   
    htmlwidgets       0.8     
    httpuv            1.3.3   
    httr              1.2.1   
    iterators         1.0.8   
    jsonlite          1.4     
    labeling          0.3     
    lattice           0.20-34 
    lazyeval          0.2.0   
    leaflet           1.1.0   
    lubridate         1.6.0   
    magrittr          1.5     
    maps              3.1.1   
    maptools          0.9-2   
    markdown          0.7.7   
    metricsgraphics   0.9.0   
    mime              0.5     
    mnormt            1.5-5   
    modelr            0.1.0   
    mongolite         0.9.1   
    munsell           0.4.3   
    nlme              3.1-128 
    openssl           0.9.6   
    packrat           0.4.8-1 
    plyr              1.8.4   
    png               0.1-7   
    psych             1.6.12  
    purrr             0.2.2   
    raster            2.5-8   
    readr             1.0.0   
    readxl            0.1.1   
    reshape2          1.4.2   
    rgdal             1.2-6   
    rgeos             0.3-23  
    rvest             0.3.2   
    scales            0.4.1   
    selectr           0.3-1   
    shiny             1.0.0   
    shinyBS           0.61    
    sourcetools       0.1.5   
    sp                1.2-1   
    stringi           1.1.2   
    stringr           1.2.0   
    tibble            1.2     
    tidyr             0.6.1   
    tidyverse         1.1.1   
    viridis           0.3.4   
    xml2              1.1.1   
    xtable            1.8-2   
    xts               0.9-7   
    yaml              2.1.14  
    zoo               1.7-14  

Fetching sources for BH (1.62.0-1) ... OK (CRAN current)
Fetching sources for DBI (0.6) ... OK (CRAN archived)
Fetching sources for DT (0.2) ... OK (CRAN current)
Fetching sources for MASS (7.3-45) ... OK (CRAN archived)
Fetching sources for R6 (2.2.0) ... OK (CRAN archived)
Fetching sources for RColorBrewer (1.1-2) ... OK (CRAN current)
Fetching sources for Rcpp (0.12.10) ... OK (CRAN archived)
Fetching sources for TeachingDemos (2.10) ... OK (CRAN current)
Fetching sources for V8 (1.5) ... OK (CRAN current)
Fetching sources for assertthat (0.1) ... OK (CRAN archived)
Fetching sources for base64enc (0.1-3) ... OK (CRAN current)
Fetching sources for broom (0.4.2) ... OK (CRAN current)
Fetching sources for codetools (0.2-15) ... OK (CRAN current)
Fetching sources for colorspace (1.3-2) ... OK (CRAN current)
Fetching sources for crosstalk (1.0.0) ... OK (CRAN current)
Fetching sources for curl (2.5) ... OK (CRAN archived)
Fetching sources for dichromat (2.0-0) ... OK (CRAN current)
Fetching sources for digest (0.6.12) ... OK (CRAN current)
Fetching sources for dplyr (0.5.0) ... OK (CRAN archived)
Fetching sources for dygraphs (1.1.1.4) ... OK (CRAN current)
Fetching sources for forcats (0.2.0) ... OK (CRAN current)
Fetching sources for foreach (1.4.3) ... OK (CRAN current)
Fetching sources for foreign (0.8-67) ... OK (CRAN archived)
Fetching sources for geojsonio (0.3.2) ... OK (CRAN archived)
Fetching sources for ggplot2 (2.2.1) ... OK (CRAN current)
Fetching sources for ggvis (0.4.3) ... OK (CRAN current)
Fetching sources for gridExtra (2.2.1) ... OK (CRAN current)
Fetching sources for gtable (0.2.0) ... OK (CRAN current)
Fetching sources for haven (1.0.0) ... OK (CRAN archived)
Fetching sources for hms (0.3) ... OK (CRAN current)
Fetching sources for htmltools (0.3.5) ... OK (CRAN archived)
Fetching sources for htmlwidgets (0.8) ... OK (CRAN archived)
Fetching sources for httpuv (1.3.3) ... OK (CRAN archived)
Fetching sources for httr (1.2.1) ... OK (CRAN current)
Fetching sources for iterators (1.0.8) ... OK (CRAN current)
Fetching sources for jsonlite (1.4) ... OK (CRAN archived)
Fetching sources for labeling (0.3) ... OK (CRAN current)
Fetching sources for lattice (0.20-34) ... OK (CRAN archived)
Fetching sources for lazyeval (0.2.0) ... OK (CRAN current)
Fetching sources for leaflet (1.1.0) ... OK (CRAN current)
Fetching sources for lubridate (1.6.0) ... OK (CRAN current)
Fetching sources for magrittr (1.5) ... OK (CRAN current)
Fetching sources for maps (3.1.1) ... OK (CRAN archived)
Fetching sources for maptools (0.9-2) ... OK (CRAN current)
Fetching sources for markdown (0.7.7) ... OK (CRAN archived)
Fetching sources for metricsgraphics (0.9.0) ... OK (CRAN current)
Fetching sources for mime (0.5) ... OK (CRAN current)
Fetching sources for mnormt (1.5-5) ... OK (CRAN current)
Fetching sources for modelr (0.1.0) ... OK (CRAN archived)
Fetching sources for mongolite (0.9.1) ... OK (CRAN archived)
Fetching sources for munsell (0.4.3) ... OK (CRAN current)
Fetching sources for nlme (3.1-128) ... OK (CRAN archived)
Fetching sources for openssl (0.9.6) ... OK (CRAN current)
Fetching sources for packrat (0.4.8-1) ... OK (CRAN current)
Fetching sources for plyr (1.8.4) ... OK (CRAN current)
Fetching sources for png (0.1-7) ... OK (CRAN current)
Fetching sources for psych (1.6.12) ... OK (CRAN archived)
Fetching sources for purrr (0.2.2) ... OK (CRAN archived)
Fetching sources for raster (2.5-8) ... OK (CRAN current)
Fetching sources for readr (1.0.0) ... OK (CRAN archived)
Fetching sources for readxl (0.1.1) ... OK (CRAN archived)
Fetching sources for reshape2 (1.4.2) ... OK (CRAN current)
Fetching sources for rgdal (1.2-6) ... OK (CRAN archived)
Fetching sources for rgeos (0.3-23) ... OK (CRAN current)
Fetching sources for rvest (0.3.2) ... OK (CRAN current)
Fetching sources for scales (0.4.1) ... OK (CRAN current)
Fetching sources for selectr (0.3-1) ... OK (CRAN current)
Fetching sources for shiny (1.0.0) ... OK (CRAN archived)
Fetching sources for shinyBS (0.61) ... OK (CRAN current)
Fetching sources for sourcetools (0.1.5) ... OK (CRAN archived)
Fetching sources for sp (1.2-1) ... OK (CRAN archived)
Fetching sources for stringi (1.1.2) ... OK (CRAN archived)
Fetching sources for stringr (1.2.0) ... OK (CRAN current)
Fetching sources for tibble (1.2) ... OK (CRAN archived)
Fetching sources for tidyr (0.6.1) ... OK (CRAN archived)
Fetching sources for tidyverse (1.1.1) ... OK (CRAN current)
Fetching sources for viridis (0.3.4) ... OK (CRAN archived)
Fetching sources for xml2 (1.1.1) ... OK (CRAN current)
Fetching sources for xtable (1.8-2) ... OK (CRAN current)
Fetching sources for xts (0.9-7) ... OK (CRAN archived)
Fetching sources for yaml (2.1.14) ... OK (CRAN current)
Fetching sources for zoo (1.7-14) ... OK (CRAN archived)
Snapshot written to '/home/production/dev/apps_src/KLIP_NDVI_v02/packrat/packrat.lock'
Installing BH (1.62.0-1) ... 
    OK (built source)
Installing DBI (0.6) ... 
    OK (built source)
Installing MASS (7.3-45) ... 
    OK (built source)
Installing R6 (2.2.0) ... 
    OK (built source)
Installing RColorBrewer (1.1-2) ... 
    OK (built source)
Installing Rcpp (0.12.10) ... 
    OK (built source)
Installing TeachingDemos (2.10) ... 
    OK (built source)
Installing assertthat (0.1) ... 
    OK (built source)
Installing base64enc (0.1-3) ... 
    OK (built source)
Installing codetools (0.2-15) ... 
    OK (built source)
Installing colorspace (1.3-2) ... 
    OK (built source)
Installing curl (2.5) ... 
    OK (built source)
Installing dichromat (2.0-0) ... 
    OK (built source)
Installing digest (0.6.12) ... 
    OK (built source)
Installing foreign (0.8-67) ... 
    OK (built source)
Installing gtable (0.2.0) ... 
    OK (built source)
Installing hms (0.3) ... 
    OK (built source)
Installing iterators (1.0.8) ... 
    OK (built source)
Installing jsonlite (1.4) ... 

Attaching package: ‘jsonlite’

The following object is masked from ‘package:purrr’:

    flatten

The following object is masked from ‘package:geojsonio’:

    validate

The following object is masked from ‘package:shiny’:

    validate

    OK (built source)
Installing labeling (0.3) ... 
    OK (built source)
Installing lattice (0.20-34) ... 
    OK (built source)
Installing lazyeval (0.2.0) ... 

Attaching package: ‘lazyeval’

The following objects are masked from ‘package:purrr’:

    is_atomic, is_formula

    OK (built source)
Installing magrittr (1.5) ... 
    OK (built source)
Installing maps (3.1.1) ... 

Attaching package: ‘maps’

The following object is masked from ‘package:purrr’:

    map

    OK (built source)
Installing mime (0.5) ... 
    OK (built source)
Installing mnormt (1.5-5) ... 
    OK (built source)
Installing openssl (0.9.6) ... 
    OK (built source)
Installing packrat (0.4.8-1) ... 
    OK (built source)
Installing png (0.1-7) ... 
    OK (built source)
Installing sourcetools (0.1.5) ... 
    OK (built source)
Installing stringi (1.1.2) ... 
    OK (built source)
Installing xtable (1.8-2) ... 
    OK (built source)
Installing yaml (2.1.14) ... 
    OK (built source)
Installing httpuv (1.3.3) ... 
    OK (built source)
Installing plyr (1.8.4) ... 
    OK (built source)
Installing readxl (0.1.1) ... 
    OK (built source)
Installing xml2 (1.1.1) ... 
    OK (built source)
Installing munsell (0.4.3) ... 
    OK (built source)
Installing htmltools (0.3.5) ... 
    OK (built source)
Installing gridExtra (2.2.1) ... 
    OK (built source)
Installing foreach (1.4.3) ... 
foreach: simple, scalable parallel programming from Revolution Analytics
Use Revolution R for scalability, fault tolerance and more.
http://www.revolutionanalytics.com

Attaching package: ‘foreach’

The following objects are masked from ‘package:purrr’:

    accumulate, when

    OK (built source)
Installing V8 (1.5) ... 
    OK (built source)
Installing nlme (3.1-128) ... 
    OK (built source)
Installing sp (1.2-1) ... 
Error: package ‘sp’ is required by ‘raster’ so will not be detached

I am using RStudio Server on Amazon EC2 instance. I have multiple R projects and for some of them packrat works perfectly fine, but for most of them it does not.

Here is the output of the sessionInfo for this specific project:

R version 3.3.2 (2016-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Amazon Linux AMI 2017.03

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8   
 [6] LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] parallel  stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] foreach_1.4.3         htmltools_0.3.5       maps_3.1.1            lazyeval_0.2.0        jsonlite_1.4          TeachingDemos_2.10   
 [7] RColorBrewer_1.1-2    raster_2.5-8          DT_0.2                htmlwidgets_0.8       xts_0.9-7             zoo_1.7-14           
[13] dygraphs_1.1.1.4      leaflet_1.1.0         shinyBS_0.61          mongolite_0.9.1       lubridate_1.6.0       dplyr_0.5.0          
[19] purrr_0.2.2           readr_1.0.0           tidyr_0.6.1           tibble_1.2            ggplot2_2.2.1         tidyverse_1.1.1      
[25] ggvis_0.4.3           metricsgraphics_0.9.0 geojsonio_0.3.2       rgdal_1.2-6           sp_1.2-1              shiny_1.0.0          

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.10     lattice_0.20-34  packrat_0.4.8-1  assertthat_0.1   digest_0.6.12    psych_1.6.12     V8_1.5           mime_0.5        
 [9] R6_2.2.0         plyr_1.8.4       httr_1.2.1       curl_2.5         readxl_0.1.1     stringr_1.2.0    foreign_0.8-67   munsell_0.4.3   
[17] broom_0.4.2      httpuv_1.3.3     modelr_0.1.0     mnormt_1.5-5     rgeos_0.3-23     codetools_0.2-15 grid_3.3.2       nlme_3.1-128    
[25] xtable_1.8-2     gtable_0.2.0     DBI_0.6          magrittr_1.5     scales_0.4.1     stringi_1.1.2    reshape2_1.4.2   xml2_1.1.1      
[33] iterators_1.0.8  tools_3.3.2      forcats_0.2.0    hms_0.3          crosstalk_1.0.0  yaml_2.1.14      colorspace_1.3-2 maptools_0.9-2  
[41] rvest_0.3.2      haven_1.0.0
alisol86 commented 7 years ago

I start to wonder where the packages are attached from in the section other attached packages? Because there sp and rgdal versions are sp_1.2-1 and rgdal_1.2-6, however when I do packageVersion("sp") in RStudio, it gives ‘1.2.4’ and packageVersion("rgdal") gives ‘1.2.8’. Does it have to do with this?

kevinushey commented 7 years ago

I'm also surprised that some of these packages appear to be getting attached while they are installed -- that seems unintended on Packrat's part. (I know that Packrat attempts to detect if the package you're attempting to install is currently attached, and detaches + unloads it if possible, so there may be something going awry in that code path)

Does it make a difference if you try restoring this project using the current development version of Packrat?

alisol86 commented 7 years ago

I uninstalled packrat and reinstalled the development version using devtools::install_github("rstudio/packrat"), if that's what you mean. Nothing changed! Now I get the same error I was getting at the first place:

packrat::init(options = list(vcs.ignore.src = TRUE)) 
Initializing packrat project in directory: - "~/dev/apps_src/KLIP_NDVI_v02" 
Error in isNamespaceLoaded(pkg) :    attempt to use zero-length variable name 
In addition: Warning message: In FUN(X[[i]], ...) : Package '' not available in repository or locally

However, sessionInfo() is giving me different results this time:

R version 3.3.2 (2016-10-31) 
Platform: x86_64-pc-linux-gnu (64-bit) 
Running under: Amazon Linux AMI 2017.03  

locale:  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8     [6] LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C        

attached base packages: 
[1] stats     graphics  grDevices utils     datasets  methods   base       

other attached packages: 
[1] devtools_1.13.2  

loaded via a namespace (and not attached): 
[1] httr_1.2.1       magrittr_1.5     R6_2.2.0         assertthat_0.1   DBI_0.6   tools_3.3.2      withr_1.0.2      rstudioapi_0.6    [9] dplyr_0.5.0      curl_2.8.1       tibble_1.2       memoise_1.1.0    Rcpp_0.12.10     git2r_0.19.0     digest_0.6.12    packrat_0.4.8-22

So you see that sp and raster packages are not attached anymore, but giving me a different error inisNamespaceLoaded(pkg). I wonder if it has to do with the .libPaths() or something, but have no idea how to fix it.

kevinushey commented 7 years ago

The error here is different from the one you reported in the earlier bit re: sp and raster, so at least that's something ...?

Is there any chance you can get an R traceback here? E.g. options(error = traceback), run the Packrat code you're executing, and then report what you see? Or even options(error = recover), and explore the stack to see further what variables are in use.

shapiromatron commented 7 years ago

Code example: https://github.com/tosaddler/plate-viewer (deleted the old packrat folder and created from scratch).

I'm getting the same error. None of my bundles work w/ the current project. When I try to rebuild from scratch, I get the error above:

> sessionInfo()
R version 3.3.3 (2017-03-06)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X El Capitan 10.11.6

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     

loaded via a namespace (and not attached):
[1] tools_3.3.3     packrat_0.4.8-1

> options(error = traceback)

> packrat::init()
Initializing packrat project in directory:
- "~/dev/plate-viewer"
Error in isNamespaceLoaded(pkg) : 
  attempt to use zero-length variable name
In addition: Warning message:
In FUN(X[[i]], ...) : Package '' not available in repository or locally
10: isNamespaceLoaded(pkg)
9: find.package(pkg, lib.loc, quiet = TRUE)
8: FUN(X[[i]], ...)
7: lapply(pkgNames, function(pkg) {
       loc <- find.package(pkg, lib.loc, quiet = TRUE)
       if (!length(loc)) 
           return(FALSE)
       if (!file.exists(file.path(loc, "DESCRIPTION"))) {
           warning("Package '", pkg, "' was found at library location '", 
               loc, "' but has no DESCRIPTION")
           return(FALSE)
       }
       dcf <- readDcf(file.path(loc, "DESCRIPTION"))
       "InstallSourcePath" %in% colnames(dcf)
   })
6: unlist(lapply(pkgNames, function(pkg) {
       loc <- find.package(pkg, lib.loc, quiet = TRUE)
       if (!length(loc)) 
           return(FALSE)
       if (!file.exists(file.path(loc, "DESCRIPTION"))) {
           warning("Package '", pkg, "' was found at library location '", 
               loc, "' but has no DESCRIPTION")
           return(FALSE)
       }
       dcf <- readDcf(file.path(loc, "DESCRIPTION"))
       "InstallSourcePath" %in% colnames(dcf)
   }))
5: hasSourcePathInDescription(pkgNames, lib.loc = lib.loc)
4: getPackageRecords(inferredPkgsNotInLib, project = project, available = available, 
       check.lockfile = TRUE, fallback.ok = fallback.ok)
3: snapshotImpl(project, available.packages(contrib.url(activeRepos(project))), 
       lib.loc = NULL, ignore.stale = TRUE, fallback.ok = TRUE)
2: withCallingHandlers(expr = {
       if (isPackratModeOn()) 
           off()
       packify(project = project, quiet = TRUE)
       augmentRprofile(project)
       options <- initOptions(project, opts)
       snapshotImpl(project, available.packages(contrib.url(activeRepos(project))), 
           lib.loc = NULL, ignore.stale = TRUE, fallback.ok = TRUE)
       restore(project, overwrite.dirty = TRUE, restart = FALSE)
       file.copy(instInitFilePath(), file.path(project, "packrat", 
           "init.R"))
       updateSettings(project, options)
       symlinkSystemPackages(project = project)
       message("Initialization complete!")
       if (enter) {
           setwd(project)
           if (!restart || !attemptRestart()) 
               on(project = project, clean.search.path = TRUE)
       }
       invisible()
   }, error = function(e) {
       for (i in seq_along(priorStructure)) {
           file <- names(priorStructure)[[i]]
           fileExistedBefore <- priorStructure[[i]]
           fileExistsNow <- file.exists(file)
           if (!fileExistedBefore && fileExistsNow) {
               unlink(file, recursive = TRUE)
           }
       }
   })
1: packrat::init()
kevinushey commented 7 years ago

@shapiromatron are you willing to share one of these bundles so I can try to reproduce the issue you're encountering? Or can you provide any other steps that I can follow to reproduce?

shapiromatron commented 7 years ago

Here's how to recreate, using a new instance of packrat:

cd ~/dev/tmp
git clone https://github.com/tosaddler/plate-viewer 
cd plate-viewer && rm -rf packrat
R -e "packrat::init()"

The reason I create a new one is the bundles don't work when I try to use them in shiny-server. After restoring (and turning packrat on) i get an error about libraries being unavailable, even though they're restored.

kevinushey commented 7 years ago

@shapiromatron, that works fine for me using the development version of Packrat currently on GitHub. (It is, though, quite slow given the number of packages that need to be installed.)

If you haven't already, can you try this using the development version of Packrat?

devtools::install_github("rstudio/packrat")
shapiromatron commented 7 years ago

Nope @kevinushey; still fails:

In bash:

cd ~/dev/tmp
git clone https://github.com/tosaddler/plate-viewer 
cd plate-viewer && rm -rf packrat
R

In R:

> devtools::install_github("rstudio/packrat")
Skipping install of 'packrat' from a github remote, the SHA1 (9492e748) has not changed since last install.
  Use `force = TRUE` to force installation

> packrat::init()
Initializing packrat project in directory:
- "~/dev/temp/plate-viewer"
Error in isNamespaceLoaded(pkg) :
  attempt to use zero-length variable name
In addition: Warning message:
In FUN(X[[i]], ...) : Package '' not available in repository or locally
kevinushey commented 7 years ago

I'm still not able to reproduce using the code you've supplied. :-/

What is the output of packrat:::appDependencies() when run in your project?

alisol86 commented 7 years ago

If I may add here since I am still getting the same error as well, here is the output of packrat:::appDependencies() on my side:

[1] ""                "BH"              "DBI"             "DT"              "R6"              "RColorBrewer"   
 [7] "Rcpp"            "TeachingDemos"   "V8"              "assertthat"      "base64enc"       "broom"          
[13] "cellranger"      "colorspace"      "crosstalk"       "curl"            "dichromat"       "digest"         
[19] "dplyr"           "dygraphs"        "forcats"         "foreach"         "geojsonio"       "ggplot2"        
[25] "ggvis"           "gridExtra"       "gtable"          "haven"           "hms"             "htmltools"      
[31] "htmlwidgets"     "httpuv"          "httr"            "iterators"       "jsonlite"        "labeling"       
[37] "lazyeval"        "leaflet"         "lubridate"       "magrittr"        "maps"            "maptools"       
[43] "markdown"        "metricsgraphics" "mime"            "modelr"          "mongolite"       "munsell"        
[49] "openssl"         "packrat"         "plyr"            "png"             "psych"           "purrr"          
[55] "raster"          "readr"           "readxl"          "rematch"         "reshape2"        "rgdal"          
[61] "rgeos"           "rlang"           "rvest"           "scales"          "selectr"         "shiny"          
[67] "shinyBS"         "sourcetools"     "sp"              "stringi"         "stringr"         "tibble"         
[73] "tidyr"           "tidyverse"       "viridis"         "xml2"            "xtable"          "xts"            
[79] "yaml"            "zoo"            
Warning message:
In FUN(X[[i]], ...) : Package '' not available in repository or locally

Does it have to do with the first element, which is basically an empty character?

shapiromatron commented 7 years ago

@kevinushey sorry for the delay, it's as you'd expect I think:

> packrat:::appDependencies()
 [1] ""               "BH"             "DBI"            "DEoptimR"
 [5] "DT"             "R6"             "RColorBrewer"   "Rcpp"
 [9] "TSP"            "assertthat"     "base64enc"      "bitops"
[13] "broom"          "caTools"        "cellranger"     "colorspace"
[17] "crosstalk"      "curl"           "data.table"     "dendextend"
[21] "dichromat"      "digest"         "diptest"        "dplyr"
[25] "flexmix"        "forcats"        "foreach"        "fpc"
[29] "gclus"          "gdata"          "ggplot2"        "gplots"
[33] "gridExtra"      "gtable"         "gtools"         "haven"
[37] "heatmaply"      "hexbin"         "hms"            "htmltools"
[41] "htmlwidgets"    "httpuv"         "httr"           "iterators"
[45] "jsonlite"       "kernlab"        "labeling"       "lazyeval"
[49] "lubridate"      "magrittr"       "mclust"         "mime"
[53] "modelr"         "modeltools"     "munsell"        "mvtnorm"
[57] "openssl"        "packrat"        "plotly"         "plyr"
[61] "prabclus"       "psych"          "purrr"          "qap"
[65] "readr"          "readxl"         "registry"       "rematch"
[69] "reshape2"       "rlang"          "robustbase"     "rvest"
[73] "scales"         "selectr"        "seriation"      "shiny"
[77] "shinyHeatmaply" "sourcetools"    "stringi"        "stringr"
[81] "tibble"         "tidyr"          "tidyverse"      "trimcluster"
[85] "viridis"        "viridisLite"    "whisker"        "xml2"
[89] "xtable"         "yaml"
Warning message:
In FUN(X[[i]], ...) : Package '' not available in repository or locally
kevinushey commented 7 years ago

The fact that an empty element is showing up there is surprising to me, so I'd like to know where that's coming from if possible. I can also explicitly work around it in Packrat as well, but it'd be good to know the underlying cause.

shapiromatron commented 7 years ago

Thanks, anything we can do to help? R isn't my specialty; I'm doing devops using packrat to manage dependencies for a shiny-server.

kevinushey commented 7 years ago

If you can debug and step through the call to appDependencies(), presumedly you could find the point at where the empty package name enters the list, but that would likely be rather tedious to dig in to.

I've just updated Packrat to drop empty package names that happen to enter here -- this is ultimately a bandaid but should hopefully help unblock you here.

alisol86 commented 7 years ago

After installing the development package, now I get the following error:


> packrat::init(options = list(vcs.ignore.src = TRUE)) 
Initializing packrat project in directory: - "~/dev/apps_src/KLIP_NDVI_v02" Error: Unable to retrieve package records for the following packages: 
- 'DT', 'V8', 'base64enc', 'broom', 'cellranger', 'colorspace', 'dichromat', 'dygraphs', 'forcats', 'foreach',
'geojsonio', 'ggplot2', 'gtable', 'haven', 'hms', 'iterators', 'labeling', 'leaflet', 'lubridate', 'model',
'mongolite', 'munsell', 'plyr', 'png', 'psych', 'purrr', 'raster', 'readr', 'readxl', 'rematch', 'reshape2', 'slang',
'rvest', 'scales', 'selectr', 'shinyBS', 'tidyr', 'tidyverse', 'xml2', 'xts', 'zoo' 
In addition: There were 42 warnings (use warnings() to see them)
 

 

shapiromatron commented 7 years ago

Yep, I get the same error:

> packrat::init()
Initializing packrat project in directory:
- "~/dev/temp/plate-viewer"
Error: Unable to retrieve package records for the following packages:
- 'DEoptimR', 'DT', 'TSP', 'base64enc', 'broom', 'caTools', 'crosstalk', 'data.table', 'dendextend', 'diptest', 'flexmix', 'forcats', 'fpc', 'gclus', 'gdata', 'gplots', 'gridExtra', 'gtools', 'haven', 'heatmaply', 'hexbin', 'hms', 'htmlwidgets', 'kernlab', 'lubridate', 'mclust', 'modelr', 'plotly', 'prabclus', 'psych', 'purrr', 'qap', 'readr', 'robustbase', 'rvest', 'selectr', 'seriation', 'shinyHeatmaply', 'tidyr', 'tidyverse', 'trimcluster', 'viridis', 'viridisLite'
In addition: There were 44 warnings (use warnings() to see them)
kevinushey commented 7 years ago

What is the output of getOption("repos") in your project? Can you also supply the output of warnings()?

alisol86 commented 7 years ago

On my side:

> getOption("repos")
                       CRAN 
"https://cran.rstudio.com/" 
attr(,"RStudio")
[1] TRUE

and

> warnings()
Warning messages:
1: In FUN(X[[i]], ...) : Package '' not available in repository or locally
2: In FUN(X[[i]], ...) :
  Failed to infer source for package 'DT'; using latest available version on CRAN instead
3: In FUN(X[[i]], ...) :
  Failed to infer source for package 'V8'; using latest available version on CRAN instead
4: In FUN(X[[i]], ...) :
  Failed to infer source for package 'base64enc'; using latest available version on CRAN instead
5: In FUN(X[[i]], ...) :
  Failed to infer source for package 'broom'; using latest available version on CRAN instead
6: In FUN(X[[i]], ...) :
  Failed to infer source for package 'cellranger'; using latest available version on CRAN instead
7: In FUN(X[[i]], ...) :
  Failed to infer source for package 'colorspace'; using latest available version on CRAN instead
8: In FUN(X[[i]], ...) :
  Failed to infer source for package 'dichromat'; using latest available version on CRAN instead
9: In FUN(X[[i]], ...) :
  Failed to infer source for package 'dygraphs'; using latest available version on CRAN instead
10: In FUN(X[[i]], ...) :
  Failed to infer source for package 'forcats'; using latest available version on CRAN instead
11: In FUN(X[[i]], ...) :
  Failed to infer source for package 'foreach'; using latest available version on CRAN instead
12: In FUN(X[[i]], ...) :
  Failed to infer source for package 'geojsonio'; using latest available version on CRAN instead
13: In FUN(X[[i]], ...) :
  Failed to infer source for package 'ggplot2'; using latest available version on CRAN instead
14: In FUN(X[[i]], ...) :
  Failed to infer source for package 'gtable'; using latest available version on CRAN instead
15: In FUN(X[[i]], ...) :
  Failed to infer source for package 'haven'; using latest available version on CRAN instead
16: In FUN(X[[i]], ...) :
  Failed to infer source for package 'hms'; using latest available version on CRAN instead
17: In FUN(X[[i]], ...) :
  Failed to infer source for package 'iterators'; using latest available version on CRAN instead
18: In FUN(X[[i]], ...) :
  Failed to infer source for package 'labeling'; using latest available version on CRAN instead
19: In FUN(X[[i]], ...) :
  Failed to infer source for package 'leaflet'; using latest available version on CRAN instead
20: In FUN(X[[i]], ...) :
  Failed to infer source for package 'lubridate'; using latest available version on CRAN instead
21: In FUN(X[[i]], ...) :
  Failed to infer source for package 'modelr'; using latest available version on CRAN instead
22: In FUN(X[[i]], ...) :
  Failed to infer source for package 'mongolite'; using latest available version on CRAN instead
23: In FUN(X[[i]], ...) :
  Failed to infer source for package 'munsell'; using latest available version on CRAN instead
24: In FUN(X[[i]], ...) :
  Failed to infer source for package 'plyr'; using latest available version on CRAN instead
25: In FUN(X[[i]], ...) :
  Failed to infer source for package 'png'; using latest available version on CRAN instead
26: In FUN(X[[i]], ...) :
  Failed to infer source for package 'psych'; using latest available version on CRAN instead
27: In FUN(X[[i]], ...) :
  Failed to infer source for package 'purrr'; using latest available version on CRAN instead
28: In FUN(X[[i]], ...) :
  Failed to infer source for package 'raster'; using latest available version on CRAN instead
29: In FUN(X[[i]], ...) :
  Failed to infer source for package 'readr'; using latest available version on CRAN instead
30: In FUN(X[[i]], ...) :
  Failed to infer source for package 'readxl'; using latest available version on CRAN instead
31: In FUN(X[[i]], ...) :
  Failed to infer source for package 'rematch'; using latest available version on CRAN instead
32: In FUN(X[[i]], ...) :
  Failed to infer source for package 'reshape2'; using latest available version on CRAN instead
33: In FUN(X[[i]], ...) :
  Failed to infer source for package 'rlang'; using latest available version on CRAN instead
34: In FUN(X[[i]], ...) :
  Failed to infer source for package 'rvest'; using latest available version on CRAN instead
35: In FUN(X[[i]], ...) :
  Failed to infer source for package 'scales'; using latest available version on CRAN instead
36: In FUN(X[[i]], ...) :
  Failed to infer source for package 'selectr'; using latest available version on CRAN instead
37: In FUN(X[[i]], ...) :
  Failed to infer source for package 'shinyBS'; using latest available version on CRAN instead
38: In FUN(X[[i]], ...) :
  Failed to infer source for package 'tidyr'; using latest available version on CRAN instead
39: In FUN(X[[i]], ...) :
  Failed to infer source for package 'tidyverse'; using latest available version on CRAN instead
40: In FUN(X[[i]], ...) :
  Failed to infer source for package 'xml2'; using latest available version on CRAN instead
41: In FUN(X[[i]], ...) :
  Failed to infer source for package 'xts'; using latest available version on CRAN instead
42: In FUN(X[[i]], ...) :
  Failed to infer source for package 'zoo'; using latest available version on CRAN instead
shapiromatron commented 7 years ago
> getOption("repos")
    CRAN
"@CRAN@"
> warnings()
NULL

So then I set one:


> getOption("repos")
                           CRAN
"http://cran.cnr.berkeley.edu/"
> warnings()
Warning messages:
1: In FUN(X[[i]], ...) : Package '' not available in repository or locally
2: In FUN(X[[i]], ...) :
  Failed to infer source for package 'DEoptimR'; using latest available version on CRAN instead
3: In FUN(X[[i]], ...) :
  Failed to infer source for package 'DT'; using latest available version on CRAN instead
4: In FUN(X[[i]], ...) :
  Failed to infer source for package 'TSP'; using latest available version on CRAN instead
5: In FUN(X[[i]], ...) :
  Failed to infer source for package 'base64enc'; using latest available version on CRAN instead
....
kevinushey commented 7 years ago

Okay, I can finally reproduce this. It looks like an unfortunately silly bug on Packrat's end. I'll try to get this fixed up shortly!

shapiromatron commented 7 years ago

Thanks Kevin for working with us and getting this patched, I hope we've been helpful in helping you diagnose!

kevinushey commented 7 years ago

You've been very helpful! Thanks for your persistence in helping me nail this down.

alisol86 commented 7 years ago

I also appreciate your efforts Kevin for working this out. I was wondering if you already managed to fix the issue as I already see you made a commit? I am getting the following error at the moment:

> packrat::init()
Initializing packrat project in directory:
- "~/dev/apps_src/KLIP_NDVI_v02"
Error in isNamespaceLoaded(pkg) : 
  attempt to use zero-length variable name
In addition: There were 50 or more warnings (use warnings() to see the first 50) 
kevinushey commented 7 years ago

Can you please run that again with options(error = traceback) set first? Also, what is the output of packrat:::appDependencies() in your project?

alisol86 commented 7 years ago

I get No traceback available after setting options(error = traceback)

> packrat::init(options = list(vcs.ignore.src = TRUE))
Initializing packrat project in directory:
- "~/dev/apps_src/KLIP_NDVI_v02"
Error in isNamespaceLoaded(pkg) : 
  attempt to use zero-length variable name
In addition: There were 50 or more warnings (use warnings() to see the first 50)
No traceback available 

In the output of appDependencies, the empty package element does not show up anymore in the beginning, but there is still a warning message at the end:

> packrat:::appDependencies()
 [1] "BH"              "DBI"             "DT"              "R6"              "RColorBrewer"    "Rcpp"           
 [7] "TeachingDemos"   "V8"              "assertthat"      "base64enc"       "broom"           "cellranger"     
[13] "colorspace"      "crosstalk"       "curl"            "dichromat"       "digest"          "dplyr"          
[19] "dygraphs"        "forcats"         "foreach"         "geojsonio"       "ggplot2"         "ggvis"          
[25] "gridExtra"       "gtable"          "haven"           "hms"             "htmltools"       "htmlwidgets"    
[31] "httpuv"          "httr"            "iterators"       "jsonlite"        "labeling"        "lazyeval"       
[37] "leaflet"         "lubridate"       "magrittr"        "maps"            "maptools"        "markdown"       
[43] "metricsgraphics" "mime"            "modelr"          "mongolite"       "munsell"         "openssl"        
[49] "packrat"         "plyr"            "png"             "psych"           "purrr"           "raster"         
[55] "readr"           "readxl"          "rematch"         "reshape2"        "rgdal"           "rgeos"          
[61] "rlang"           "rvest"           "scales"          "selectr"         "shiny"           "shinyBS"        
[67] "sourcetools"     "sp"              "stringi"         "stringr"         "tibble"          "tidyr"          
[73] "tidyverse"       "viridis"         "xml2"            "xtable"          "xts"             "yaml"           
[79] "zoo"            
Warning message:
In FUN(X[[i]], ...) : Package '' not available in repository or locally
kevinushey commented 7 years ago

Any chance you can post your application publicly, so I can try to reproduce?

shapiromatron commented 7 years ago

Hi @kevinushey I'm getting the same issues on my project which is public:

> getOption("repos")
                                CRAN
"https://mirrors.nics.utk.edu/cran/"

> options(error = traceback)

> packrat::init()
Initializing packrat project in directory:
- "~/dev/temp/plate-viewer"
Error in isNamespaceLoaded(pkg) :
  attempt to use zero-length variable name
In addition: There were 47 warnings (use warnings() to see them)
No traceback available

> packrat:::appDependencies()
 [1] "BH"             "DBI"            "DEoptimR"       "DT"
 [5] "R6"             "RColorBrewer"   "Rcpp"           "TSP"
 [9] "assertthat"     "base64enc"      "bitops"         "broom"
[13] "caTools"        "cellranger"     "colorspace"     "crosstalk"
[17] "curl"           "data.table"     "dendextend"     "dichromat"
[21] "digest"         "diptest"        "dplyr"          "flexmix"
[25] "forcats"        "foreach"        "fpc"            "gclus"
[29] "gdata"          "ggplot2"        "gplots"         "gridExtra"
[33] "gtable"         "gtools"         "haven"          "heatmaply"
[37] "hexbin"         "hms"            "htmltools"      "htmlwidgets"
[41] "httpuv"         "httr"           "iterators"      "jsonlite"
[45] "kernlab"        "labeling"       "lazyeval"       "lubridate"
[49] "magrittr"       "mclust"         "mime"           "modelr"
[53] "modeltools"     "munsell"        "mvtnorm"        "openssl"
[57] "packrat"        "plotly"         "plyr"           "prabclus"
[61] "psych"          "purrr"          "qap"            "readr"
[65] "readxl"         "registry"       "rematch"        "reshape2"
[69] "rlang"          "robustbase"     "rvest"          "scales"
[73] "selectr"        "seriation"      "shiny"          "shinyHeatmaply"
[77] "sourcetools"    "stringi"        "stringr"        "tibble"
[81] "tidyr"          "tidyverse"      "trimcluster"    "viridis"
[85] "viridisLite"    "whisker"        "xml2"           "xtable"
[89] "yaml"
Warning message:
In FUN(X[[i]], ...) : Package '' not available in repository or locally
alisol86 commented 7 years ago

Thank you @shapiromatron for sharing your project, as my application is used for commercial purposed and I needed to go through administration process to be able to share it, which would normally take much longer!

Let's hope that @kevinushey would be able to reproduce the error with your project.

shapiromatron commented 7 years ago

Oh yeah, I forgot to show the warnings. They were like the ones above...

In FUN(X[[i]], ...) :
  Failed to infer source for package 'DEoptimR'; using latest available version on CRAN instead
kevinushey commented 7 years ago

The warnings here can be safely ignored, and I still cannot reproduce the isNamespaceLoaded() error described when using packrat with the plate-viewer repository.

One last thing to try -- can you try running:

trace(isNamespaceLoaded, quote({
    calls <- capture.output(sys.calls())
    writeLines(calls, "~/rstudio-trace.txt")
}))
packrat::init()

Hopefully, when the error occurs, you will get a stack trace written to the file at ~/rstudio-trace.txt. Could you then share the contents of that file?

alisol86 commented 7 years ago

Here you go:

[[1]]
(function (name, version) 
{
    .rs.isPackageInstalled(name) && (.rs.getPackageVersion(name) >= 
        version)
})("sparklyr", "0.2.5")

[[2]]
.rs.isPackageInstalled(name)

[[3]]
vapply(name, FUN.VALUE = character(1), USE.NAMES = FALSE, function(pkg) {
    system.file(package = pkg, lib.loc = libLoc)
})

[[4]]
FUN(X[[i]], ...)

[[5]]
system.file(package = pkg, lib.loc = libLoc)

[[6]]
find.package(package, lib.loc, quiet = TRUE)

[[7]]
isNamespaceLoaded(pkg)

[[8]]
.doTrace({
    calls <- capture.output(sys.calls())
    writeLines(calls, "~/rstudio-trace.txt")
}, "on entry")

[[9]]
eval.parent(exprObj)

[[10]]
eval(expr, p)

[[11]]
eval(expr, envir, enclos)

[[12]]
capture.output(sys.calls())

[[13]]
evalVis(expr)

[[14]]
withVisible(eval(expr, pf))

[[15]]
eval(expr, pf)

[[16]]
eval(expr, envir, enclos)
kevinushey commented 7 years ago

Can you try running it in a plain R session (outside of RStudio)? Unfortunately RStudio is executing isNamespaceLoaded() behind the hood and that seems to be masking the crash that's occurring.

alisol86 commented 7 years ago

Sorry, I wasn't sure what to expect from the output. Here is the output when running in R, hope this one helps!

[[1]]
packrat::init("~/dev/apps_src/KLIP_NDVI_v02/")

[[2]]
withCallingHandlers(expr = {
    if (isPackratModeOn()) 
        off()
    packify(project = project, quiet = TRUE)
    augmentRprofile(project)
    options <- initOptions(project, opts)
    snapshotImpl(project, available.packages(contrib.url(activeRepos(project))), 
        lib.loc = NULL, ignore.stale = TRUE, fallback.ok = TRUE)
    restore(project, overwrite.dirty = TRUE, restart = FALSE)
    file.copy(instInitFilePath(), file.path(project, "packrat", 
        "init.R"))
    updateSettings(project, options)
    symlinkSystemPackages(project = project)
    message("Initialization complete!")
    if (enter) {
        setwd(project)
        if (!restart || !attemptRestart()) 
            on(project = project, clean.search.path = TRUE)
    }
    invisible()
}, error = function(e) {
    for (i in seq_along(priorStructure)) {
        file <- names(priorStructure)[[i]]
        fileExistedBefore <- priorStructure[[i]]
        fileExistsNow <- file.exists(file)
        if (!fileExistedBefore && fileExistsNow) {
            unlink(file, recursive = TRUE)
        }
    }
})

[[3]]
snapshotImpl(project, available.packages(contrib.url(activeRepos(project))), 
    lib.loc = NULL, ignore.stale = TRUE, fallback.ok = TRUE)

[[4]]
getPackageRecords(inferredPkgsNotInLib, project = project, available = available, 
    check.lockfile = TRUE, fallback.ok = fallback.ok)

[[5]]
lapply(allRecords, function(record) {
    deps <- getPackageDependencies(pkgs = record$name, lib.loc = lib.loc, 
        available.packages = available)
    if (!is.null(deps)) {
        record$depends <- getPackageRecords(deps, project = project, 
            available, TRUE, lib.loc = lib.loc, missing.package = missing.package, 
            check.lockfile = check.lockfile, fallback.ok = fallback.ok)
    }
    record
})

[[6]]
FUN(X[[i]], ...)

[[7]]
getPackageRecords(deps, project = project, available, TRUE, lib.loc = lib.loc, 
    missing.package = missing.package, check.lockfile = check.lockfile, 
    fallback.ok = fallback.ok)

[[8]]
lapply(allRecords, function(record) {
    deps <- getPackageDependencies(pkgs = record$name, lib.loc = lib.loc, 
        available.packages = available)
    if (!is.null(deps)) {
        record$depends <- getPackageRecords(deps, project = project, 
            available, TRUE, lib.loc = lib.loc, missing.package = missing.package, 
            check.lockfile = check.lockfile, fallback.ok = fallback.ok)
    }
    record
})

[[9]]
FUN(X[[i]], ...)

[[10]]
getPackageRecords(deps, project = project, available, TRUE, lib.loc = lib.loc, 
    missing.package = missing.package, check.lockfile = check.lockfile, 
    fallback.ok = fallback.ok)

[[11]]
hasSourcePathInDescription(pkgNames, lib.loc = lib.loc)

[[12]]
unlist(lapply(pkgNames, function(pkg) {
    loc <- find.package(pkg, lib.loc, quiet = TRUE)
    if (!length(loc)) 
        return(FALSE)
    if (!file.exists(file.path(loc, "DESCRIPTION"))) {
        warning("Package '", pkg, "' was found at library location '", 
            loc, "' but has no DESCRIPTION")
        return(FALSE)
    }
    dcf <- readDcf(file.path(loc, "DESCRIPTION"))
    "InstallSourcePath" %in% colnames(dcf)
}))

[[13]]
lapply(pkgNames, function(pkg) {
    loc <- find.package(pkg, lib.loc, quiet = TRUE)
    if (!length(loc)) 
        return(FALSE)
    if (!file.exists(file.path(loc, "DESCRIPTION"))) {
        warning("Package '", pkg, "' was found at library location '", 
            loc, "' but has no DESCRIPTION")
        return(FALSE)
    }
    dcf <- readDcf(file.path(loc, "DESCRIPTION"))
    "InstallSourcePath" %in% colnames(dcf)
})

[[14]]
FUN(X[[i]], ...)

[[15]]
find.package(pkg, lib.loc, quiet = TRUE)

[[16]]
isNamespaceLoaded(pkg)

[[17]]
.doTrace({
    calls <- capture.output(sys.calls())
    writeLines(calls, "~/rstudio-trace.txt")
}, "on entry")

[[18]]
eval.parent(exprObj)

[[19]]
eval(expr, p)

[[20]]
eval(expr, envir, enclos)

[[21]]
capture.output(sys.calls())

[[22]]
evalVis(expr)

[[23]]
withVisible(eval(expr, pf))

[[24]]
eval(expr, pf)

[[25]]
eval(expr, envir, enclos)
kevinushey commented 7 years ago

@alisol86 what is the output of packrat:::appDependencies() in your project? Did you update to the latest version of Packrat on GitHub already?

devtools::install_github("rstudio/packrat")

It seems like, on your system, Packrat is still picking up "" as a package name (and I still have no idea why this could be the case).

pokyah commented 7 years ago

Hi all ! I've the same problem.

While running : packrat::init(getwd())

I get the following error :

Error in isNamespaceLoaded(pkg) : 
  attempt to use zero-length variable name
In addition: Warning message:
In FUN(X[[i]], ...) : Package '' not available in repository or locally

Here is the result of : packrat:::appDependencies() :

[1] ""             "BH"           "DBI"          "R6"           "RColorBrewer" "RPostgreSQL"  "Rcpp"         "assertthat"   "bindr"       
[10] "bindrcpp"     "broom"        "cellranger"   "colorspace"   "curl"         "devtools"     "dichromat"    "digest"       "dplyr"       
[19] "forcats"      "ggplot2"      "git2r"        "glue"         "gridExtra"    "gtable"       "haven"        "hms"          "httr"        
[28] "jsonlite"     "labeling"     "lattice"      "lazyeval"     "lubridate"    "magrittr"     "memoise"      "mime"         "modelr"      
[37] "munsell"      "openssl"      "packrat"      "pkgconfig"    "plogr"        "plyr"         "psych"        "purrr"        "readr"       
[46] "readxl"       "rematch"      "reshape2"     "rlang"        "rstudioapi"   "rvest"        "scales"       "selectr"      "stringi"     
[55] "stringr"      "tibble"       "tidyr"        "tidyselect"   "tidyverse"    "whisker"      "withr"        "xml2"       

here are my session info : `R version 3.3.1 (2016-06-21) Platform: x86_64-suse-linux-gnu (64-bit) Running under: openSUSE Leap 42.2

locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8
[6] LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages: [1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached): [1] httr_1.3.0 R6_2.2.2 tools_3.3.1 withr_2.0.0 curl_2.8.1 memoise_1.1.0 git2r_0.19.0 digest_0.6.12
[9] packrat_0.4.8-30 devtools_1.13.3 `

Also, I've noticed that while I run : packrat::init(getwd())

An .Rprofile appears in my Working Directory and immediately disappears.

I hope that helps to solve the problem...

many thanks for your support !

EDIT : if i do the same in a brand new folder, I don't get the problem. I guess there should be something wrong inside a project but not globally.

alisol86 commented 7 years ago

@kevinushey: I check my packrat version through:

> packageVersion("packrat")                  
[1] ‘0.4.8.30’

I assume this is the development version, right? Also now I get the same error as before and the content of rstudio-trace.txt is same as before (https://github.com/rstudio/packrat/issues/314#issuecomment-322987354). Regarding the output of packrat:::appDependencies(), when I do it in plain R session, I get the following results which is different than before with many more packages this time and the first element doesn't appear to be an empty package (which presumably causes the problem):

> packrat:::appDependencies()
  [1] "BH"                   "BsMD"                 "DAAG"                
  [4] "DBI"                  "DT"                   "DoE.base"            
  [7] "FNN"                  "Formula"              "FrF2"                
 [10] "GISTools"             "GLMMGibbs"            "GPArotation"         
 [13] "GhcnDaily"            "Hmisc"                "Kendall"             
 [16] "Lahman"               "LearnBayes"           "MatrixModels"        
 [19] "ModelMetrics"         "NISTunits"            "PKI"                 
 [22] "R.methodsS3"          "R.oo"                 "R.utils"             
 [25] "R6"                   "R6testA"              "RANN"                
 [28] "RColorBrewer"         "RCurl"                "RGtk2"               
 [31] "RJDBC"                "RJSONIO"              "RPostgreSQL"         
 [34] "RPostgres"            "RSQLite"              "RUnit"               
 [37] "Rcpp"                 "RcppArmadillo"        "RcppEigen"           
 [40] "RcppGSL"              "RgoogleMaps"          "RpostgreSQL"         
 [43] "ShinyDash"            "SparseM"              "StanHeaders"         
 [46] "Sxslt"                "TH.data"              "TTR"                 
 [49] "TeachingDemos"        "V8"                   "XLConnect"           
 [52] "XLConnectJars"        "XML"                  "abc"                 
 [55] "abc.data"             "abind"                "acepack"             
 [58] "akima"                "animation"            "arm"                 
 [61] "assertive.base"       "assertive.numbers"    "assertive.properties"
 [64] "assertive.sets"       "assertthat"           "backports"           
 [67] "base64enc"            "bayesplot"            "bdsmatrix"           
 [70] "bit"                  "bit64"                "bitops"              
 [73] "blob"                 "bread"                "breakfast"           
 [76] "brew"                 "broom"                "caTools"             
 [79] "car"                  "caret"                "cellranger"          
 [82] "changepoint"          "checkmate"            "chron"               
 [85] "classInt"             "coda"                 "colorspace"          
 [88] "colourpicker"         "combinat"             "conf.design"         
 [91] "countrycode"          "crayon"               "crosstalk"           
 [94] "cshapes"              "curl"                 "data.table"          
 [97] "def"                  "deldir"               "devtools"            
[100] "dichromat"            "digest"               "doMC"                
[103] "doParallel"           "dotCall64"            "dplyr"               
[106] "dygraphs"             "e1071"                "estimability"        
[109] "evaluate"             "expm"                 "fastICA"             
[112] "foo"                  "forcats"              "foreach"             
[115] "gWidgetsWWW2"         "gam"                  "gdalUtils"           
[118] "gdata"                "gee"                  "geojsonio"           
[121] "geojsonlint"          "geosphere"            "ggforce"             
[124] "ggmap"                "ggplot2"              "ggvis"               
[127] "ghi"                  "git2r"                "glue"                
[130] "gmodels"              "gridBase"             "gridExtra"           
[133] "gstat"                "gtable"               "gtools"              
[136] "h5"                   "haven"                "hexbin"              
[139] "highlight"            "highr"                "hms"                 
[142] "htmlTable"            "htmltools"            "htmlwidgets"         
[145] "httpuv"               "httr"                 "ibdreg"              
[148] "igraph"               "inline"               "intervals"           
[151] "irlba"                "iterators"            "jkl"                 
[154] "jose"                 "jpeg"                 "jsonlite"            
[157] "jsonvalidate"         "kernlab"              "knitr"               
[160] "labeling"             "latticeExtra"         "lazyeval"            
[163] "leaflet"              "lme4"                 "lmtest"              
[166] "locfit"               "loo"                  "lsmeans"             
[169] "lubridate"            "magrittr"             "mailR"               
[172] "mapproj"              "maps"                 "maptools"            
[175] "mapview"              "markdown"             "matrixStats"         
[178] "matrixcalc"           "maxLik"               "mda"                 
[181] "measurements"         "memoise"              "metricsgraphics"     
[184] "mi"                   "microbenchmark"       "mime"                
[187] "miniUI"               "minqa"                "miscTools"           
[190] "mlbench"              "modelr"               "mondate"             
[193] "mongolite"            "multcomp"             "munsell"             
[196] "mvtnorm"              "nasaweather"          "ncdf"                
[199] "ncdf4"                "nloptr"               "numbers"             
[202] "nycflights13"         "oatmeal"              "openssl"             
[205] "osmar"                "packrat"              "pbkrtest"            
[208] "pkgA"                 "pkgB"                 "pkgconfig"           
[211] "plm"                  "plogr"                "plyr"                
[214] "png"                  "polspline"            "pracma"              
[217] "praise"               "proto"                "pryr"                
[220] "psych"                "purrr"                "quadprog"            
[223] "quantmod"             "quantreg"             "rJava"               
[226] "rPython"              "randomForest"         "raster"              
[229] "rasterVis"            "rbenchmark"           "readr"               
[232] "readxl"               "rematch"              "reshape2"            
[235] "rgdal"                "rgeos"                "rggobi"              
[238] "rgl"                  "rhandsontable"        "rjson"               
[241] "rlang"                "rmapshaper"           "rmarkdown"           
[244] "rmongodb"             "rprojroot"            "rsconnect"           
[247] "rstan"                "rstanarm"             "rstantools"          
[250] "rstudioapi"           "rvest"                "sandwich"            
[253] "satellite"            "scales"               "scatterplot3d"       
[256] "selectr"              "sem"                  "sf"                  
[259] "sfsmisc"              "shapefiles"           "shiny"               
[262] "shinyBS"              "shinyjs"              "shinystan"           
[265] "shinythemes"          "sourcetools"          "sp"                  
[268] "spacetime"            "spam"                 "spbabel"             
[271] "spdep"                "spdplyr"              "sphet"               
[274] "splm"                 "stringi"              "stringr"             
[277] "strucchange"          "testRcppClass"        "testRcppModule"      
[280] "testit"               "testthat"             "threejs"             
[283] "tibble"               "tidyr"                "tidyselect"          
[286] "tidyverse"            "timeDate"             "timeSeries"          
[289] "tis"                  "tmap"                 "tmaptools"           
[292] "tourr"                "tree"                 "tseries"             
[295] "tweenr"               "udunits2"             "units"               
[298] "vcd"                  "viridis"              "viridisLite"         
[301] "webshot"              "whisker"              "withr"               
[304] "xgobi"                "xlsx"                 "xlsxjars"            
[307] "xml2"                 "xtable"               "xts"                 
[310] "yags"                 "yaml"                 "zoo"     

However, when I do the same in RStudio, I get the following packages with the warning In FUN(X[[i]], ...) : Package '' not available in repository or locally at the end

> packrat:::appDependencies()
 [1] "BH"              "DBI"             "DT"              "R6"             
 [5] "RColorBrewer"    "Rcpp"            "TeachingDemos"   "V8"             
 [9] "assertthat"      "base64enc"       "broom"           "cellranger"     
[13] "colorspace"      "crosstalk"       "curl"            "dichromat"      
[17] "digest"          "dplyr"           "dygraphs"        "forcats"        
[21] "foreach"         "geojsonio"       "ggplot2"         "ggvis"          
[25] "glue"            "gridExtra"       "gtable"          "haven"          
[29] "hms"             "htmltools"       "htmlwidgets"     "httpuv"         
[33] "httr"            "iterators"       "jsonlite"        "labeling"       
[37] "lazyeval"        "leaflet"         "lubridate"       "magrittr"       
[41] "maps"            "maptools"        "markdown"        "metricsgraphics"
[45] "mime"            "modelr"          "mongolite"       "munsell"        
[49] "openssl"         "packrat"         "plyr"            "png"            
[53] "psych"           "purrr"           "raster"          "readr"          
[57] "readxl"          "rematch"         "reshape2"        "rgdal"          
[61] "rgeos"           "rlang"           "rvest"           "scales"         
[65] "selectr"         "shiny"           "shinyBS"         "sourcetools"    
[69] "sp"              "stringi"         "stringr"         "tibble"         
[73] "tidyr"           "tidyselect"      "tidyverse"       "viridis"        
[77] "xml2"            "xtable"          "xts"             "yaml"           
[81] "zoo"            
Warning message:
In FUN(X[[i]], ...) : Package '' not available in repository or locally

Sorry if I am posting a lot of information. I tried to put as much relevant outputs as possible and I hope this will help you to find the problem.

kevinushey commented 7 years ago

I've tried to put another bandaid here, but unfortunately I still can't reproduce this locally, and until I can I won't be able to make a fix with any confidence 😕

alisol86 commented 7 years ago

@kevinushey I am not sure if you already changed something, but with the latest version on github ‘0.4.8.31’, I managed to run the command and the error is not there anymore, which is super good news :) However, I still get an error while installing one of the packages

Installing psych (1.7.5) ... 
Error: Command failed (1)

Failed to run system command:

    '/usr/local/bin/R/3.3.2/lib64/R/bin/R' --vanilla CMD INSTALL '/tmp/RtmpI8Y5Cv/psych' --library='/home/production/dev/apps_src/KLIP_NDVI_v02/packrat/lib/x86_64-pc-linux-gnu/3.3.2' --install-tests --no-docs --no-multiarch --no-demo 

The command failed with output:
ERROR: dependency 'mnormt' is not available for package 'psych'
* removing '/home/production/dev/apps_src/KLIP_NDVI_v02/packrat/lib/x86_64-pc-linux-gnu/3.3.2/psych'
In addition: There were 50 or more warnings (use warnings() to see the first 50)

Any ideas on this?

alisol86 commented 7 years ago

I am not sure if this is linked to directories, but if I look at the error message, it seems that packrat sometimes looks into different directories. Here is the output of libPaths() in my project:

> .libPaths()
[1] "/home/production/R/x86_64-pc-linux-gnu-library/3.3" "/usr/local/bin/R/3.3.2/lib64/R/library" 

And packrat seems to be installing the package in '/usr/local/bin/R/3.3.2/lib64/R/bin/R'. Is there a way to force to install all packages in a specific directory, e.g. "/home/production/R/x86_64-pc-linux-gnu-library/3.3?

kevinushey commented 7 years ago

You might try manually installing the mnormt package and trying again:

install.packages("mnormt")
packrat::init()

I'm not sure why mnormt is not being picked up as a dependency for the psych package -- it should be there, e.g.

> tools::package_dependencies("psych")
$psych
[1] "mnormt"    "parallel"  "stats"     "graphics" 
[5] "grDevices" "methods"   "foreign"   "lattice"  
[9] "nlme"   

Could potentially be a Packrat issue?

alisol86 commented 7 years ago

@kevinushey Many thanks for your persistence and great work, I finally managed to run packrat for my project! I encountered couple of other errors which were linked to package installation, but with the current development version, everything worked for me!

I really enjoyed the discussions we had and I really appreciate your help. I wish you best of luck with your future endeavors with Packrat! 👍😃

kambanane commented 5 years ago

I get the same thing

Installing sp (1.3-1) ... Error: package ‘sp’ is required by ‘raster’ so will not be detached

No clue how to fix it. It will not create the lock file.