1

First of all, I am aware that my pain is totally self-inflicted.

In moving certain packages to the external.packages option, I first uninstalled them from packrat using remove.packages() rather than packrat::clean() as recommended here by the package author.

The code in the project works just fine (as the external packages are properly loaded in the session), but since then it has been impossible to update the library. If I try to carry out a snapshot, I get the following error

Error: Unable to retrieve package records for the following packages:
- "knitr", "rmarkdown"

I tried reinstalling the packages afresh and packrat hollered back at me

Warning in install.packages :
  packages ‘knitr’, ‘rmarkdown’ are in use and will not be installed

So, I tried to call the proper function with clean(c('knitr', 'rmarkdown'), force = TRUE) and still no way out as I got this message

Error in find.package(pkgs, lib) : 
  there are no packages called ‘knitr’, ‘rmarkdown’

I tried to check whether the packages physically exist in the packrat library and they do!

> .libPaths()
[1] "C:/Users/Admn/Documents/.../cct/packrat/lib/x86_64-w64-mingw32/3.5.1"    
[2] "C:/Users/Admn/Documents/.../cct/packrat/lib-ext/x86_64-w64-mingw32/3.5.1"
[3] "C:/Users/Admn/Documents/.../cct/packrat/lib-R/x86_64-w64-mingw32/3.5.1"  

> c('knitr', 'rmarkdown') %in% .packages(all.available = TRUE)
[1] TRUE TRUE
> c('knitr', 'rmarkdown') %in% 
      list.dirs(.libPaths()[2], full.names = FALSE, recursive = FALSE)
[1] TRUE TRUE

I am seriously tempted to manually yank out the two folders from the library directory with unlink(), but I suspect I might end up creating more problems.

If it can be avoided, I don't want to end up reinstalling the entire packrat library -- all 500MB of it -- given that I have access to painfully slow and expensive internet. Does anyone know the way out of this mess?

BroVic
  • 979
  • 9
  • 26

1 Answers1

1

Seem like the same issue here. You likely have a package that depends on knitr and/or rmarkdown. It does not seem like there is a solution to this problem where one uses external packages.

I tried reinstalling the packages afresh and packrat hollered back at me ...

Did you do it in the same session where you have packrat packrat::on()? In that case, your .libPaths() have been changed and the external packages are

... loaded from the user library upon entering packrat mode

before .libPaths() is changed. E.g., I get the following in a project that I have

packrat::get_opts("external.packages")
#R [1] "BH"
"BH" %in% .packages(all.available = TRUE)
#R [1] TRUE
"BH" %in% list.dirs(.libPaths()[1], # notice the one
                    full.names = FALSE, recursive = FALSE)
#R [1] FALSE
.libPaths()
#R [1] "/My/Path/To/My-project/packrat/lib/x86_64-w64-mingw32/3.5.1"    
#R [2] "/My/Path/To/My-project/packrat/lib-ext/x86_64-w64-mingw32/3.5.1"
#R [3] "/My/Path/To/My-project/packrat/lib-R/x86_64-w64-mingw32/3.5.1"  
packrat::off()
.libPaths()
#R [1] "/My/Path/To/R/win-library/3.5"
#R [2] "C:/Program Files/R/R-3.5.1/library"  
"BH" %in% list.dirs(.libPaths()[1], # notice the one
                    full.names = FALSE, recursive = FALSE)
#R [1] TRUE

where I turn off packrat to get back to my user library where I would be able to uninstall BH with remove.packages since from help("remove-packages")

lib a character vector giving the library directories to remove the packages from. If missing, defaults to the first element in .libPaths().

I would not be able to do this with packrat::clean since the default value to argument lib.loc is

packrat:::libDir(NULL)
#R [1] "/My/Path/To/My-project/packrat/lib/x86_64-w64-mingw32/3.5.1"

Update

The issue can be solved by the infer.dependencies arguments to packrat::snapshotas shown in the Github issue I link to at the start.

  • 1
    I recently have some use for this very project, so I will revisit it bearing in mind your contribution and let you know how it went. Thanks. – BroVic Jan 22 '19 at 16:36