1

I'm using packrat to freeze all versions of dependencies for an application. Sometimes I run into troubles with "staleness".

For instance, today I upgraded one package to a newer version. I did this by launching R in the packrat-managed project:

% R --quiet
Packrat mode on. Using library in directory:
- "~/git/myapp/app/packrat/lib"
> install.packages('MyPackage')
Installing package into ‘/Users/kwilliams/git/myapp/app/packrat/lib/x86_64-apple-darwin17.7.0/3.5.3’
(as ‘lib’ is unspecified)
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 3537k  100 3537k    0     0  5530k      0 --:--:-- --:--:-- --:--:-- 5527k
* installing *source* package ‘MyPackage’ ...
** R
** data
*** moving datasets to lazyload DB
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (MyPackage)

The downloaded source packages are in
    ‘/private/var/folders/zp/hj5hqfw970z0_78mrb_802lm0001z9/T/RtmpzfYDUz/downloaded_packages’

However, when I try to generate a new snapshot file, nothing happens:

> packrat::snapshot()
Snapshot written to '/Users/kwilliams/git/myapp/app/packrat/packrat.lock'

(The file is no different than before - the old version of MyPackage is still listed.)

I verified that the new version was indeed installed, and try the snapshot again:

> packageVersion('MyPackage')
[1] ‘7.4’
> packrat::snapshot()

The following packages are stale:
              _    
    MyPackage   7.4

These packages must be updated by calling packrat::restore() before
snapshotting. If you are sure you want the installed versions of these
packages to be snapshotted, call packrat::snapshot() again with
ignore.stale=TRUE.
--
Snapshot operation was cancelled, no changes were made.

Huh? Not sure why the different results between the two times.

status() does seem to know the situation correctly:

> packrat::status()

The following packages are out of sync between packrat and your current library:
                    packrat   library
    MyPackage   7.3.1-22287       7.4

Use packrat::snapshot() to set packrat to use the current library, or use
packrat::restore() to reset the library to the last snapshot.

I figure I'll force it, so I add ignore.stale=TRUE:

> packrat::snapshot(ignore.stale=TRUE)

Upgrading these packages already present in packrat:
                       from    to
    MyPackage   7.3.1-22287   7.4

Fetching sources for MyPackage (7.4) ... FAILED
Error in snapshotSources(project, activeRepos(project), allRecordsFlat) : 
  Errors occurred when fetching source files:
Error in getSourceForPkgRecord(pkgRecord, sourceDir, availablePkgs, repos) : 
  Could not find sources for MyPackage (7.4).

Bummer. Might this have something to do with the fact that this is a locally-created package, installed from a local CRAN-alike? This would be a packrat bug, because (as noted above) install.packages() can find the source package just fine.

So I think there are two potential packrat bugs here:

  1. Inability to snapshot the newly installed package
  2. Inability to download source for the package

FWIW, I think the first problem is identical to the situation here: https://groups.google.com/forum/#!topic/packrat-discuss/HvD45u6w4Zg, in which Kevin Ushey (author/maintainer of packrat) says "it's possible that the logic around 'stale' packages can just go away."

Ken Williams
  • 22,756
  • 10
  • 85
  • 147

1 Answers1

0

Here are the workarounds I'm using to get back on my way:

  1. As mentioned above, use ignore.stale=TRUE to force the snapshot even when it thinks things are stale.

  2. Copy the source package manually to packrat/src/MyPackage/.

Now it succeeds:

> packrat::snapshot(ignore.stale=TRUE)

Upgrading these packages already present in packrat:
                       from    to
    MyPackage   7.3.1-22287   7.4

Snapshot written to '/Users/kwilliams/git/myapp/app/packrat/packrat.lock'

The packrat/packrat.lock file has been updated correctly:

% git diff
diff --git a/app/packrat/packrat.lock b/app/packrat/packrat.lock
index 6c17020..f717d29 100644
--- a/app/packrat/packrat.lock
+++ b/app/packrat/packrat.lock
@@ -30,9 +30,9 @@ Hash: 9772da3bc51603a19a2b75f008fd63e3

 Package: MyPackage
 Source: source
-Version: 7.3.1-22287
+Version: 7.4
 SourcePath: lib/MyPackage
-Hash: 4fe20417f5711b3c7c90a4efe3bb4bc7
+Hash: 880a308537e8de571106893e839386f6
...
Ken Williams
  • 22,756
  • 10
  • 85
  • 147
  • Copying the source manually seems like playing with fire. A more cautious solution would be to copy the source to a local repo and use `packrat::set_opts(local.repos = "")` (section 'Installing local source packages' [here](https://rstudio.github.io/packrat/walkthrough.html)). – eric_kernfeld Aug 12 '19 at 22:08
  • I am interested in separating your installation problems from your snapshotting problems. What happens if you use `ignore.stale=TRUE` but don't copy the new package source into the packrat directory? – eric_kernfeld Aug 12 '19 at 22:10