R packrat快照:升级程序包会出现“过时”错误

时间:2019-05-16 21:58:31

标签: r package packrat

我正在使用packrat冻结应用程序的所有依赖关系版本。有时我会因“陈旧”而遇到麻烦。

例如,今天我将一个软件包升级到了较新的版本。我是通过在packrat管理的项目中启动R来实现的:

% 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’

但是,当我尝试生成新的快照文件时,什么也没发生:

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

(该文件与以前没有什么不同-仍列出了MyPackage的旧版本。)

我确认确实安装了新版本,然后再次尝试快照:

> 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.

嗯?不确定为什么两次之间的结果不同。

status()似乎正确地知道了这种情况:

> 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.

我认为我会强制执行,因此我添加了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).

笨蛋。这可能与从本地CRAN一样安装的本地创建的软件包有关吗?这将是一个packrat错误,因为(如上所述)install.packages()可以找到源程序包。

所以我认为这里有两个潜在的packrat错误:

  1. 无法快照新安装的软件包
  2. 无法下载软件包的源文件

FWIW,我认为第一个问题与这里的情况相同:https://groups.google.com/forum/#!topic/packrat-discuss/HvD45u6w4Zg,其中,packrat的作者/维护者Kevin Ushey说:“围绕“陈旧”软件包的逻辑很可能可以走开。”

1 个答案:

答案 0 :(得分:0)

以下是我用来恢复正常工作的解决方法:

  1. 如上所述,即使在认为事情过时的情况下,也要使用ignore.stale=TRUE强制快照。

  2. 将源包手动复制到packrat/src/MyPackage/

现在成功了:

> 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'

packrat/packrat.lock文件已正确更新:

% 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
...