在 R 3.4.0 中从二进制文件安装包

Installing packages from binary in R 3.4.0

我最近将 R 更新到最新版本:3.4.0。 R 安装在网络位置 H:/。现在当我尝试安装本地二进制包时发生了一些奇怪的事情:

  filename <- paste0("R:/path/independeR_", versions, ".zip")
  install.packages(filename,
                   repos = NULL, type = "source",
                   lib = gsub("\\\\networkpath/home/[[:alpha:]]*/",
                              "H:/", .libPaths()[1]))

H:/R:/ 都是网络位置。在 .libPaths() 中,默认位置在 H:/ 位置,但它显示了整个网络地址。在对 install.packages 的调用中,我替换了这个。

上面的代码失败,输出如下:

'\networkpath\home\JDUB~PN6\DOCU~UZL\R\R-34~TN4.0' is not recognized as an internal or external command,
operable program or batch file.
Warning in install.packages :
  running command '"//networkpath/home/JDUB~PN6/DOCU~UZL/R/R-34~TN4.0/bin/x64/R" CMD INSTALL -l "H:\Documents\R\R-3.4.0\library" "R:/path/independeR_0.1.8.zip"' had status 1
Warning in install.packages :
  installation of package ‘R:/path/independeR_0.1.8.zip’ had non-zero exit status

这里有两件事让我感到惊讶。目录名都乱七八糟(DOCU~UZL 而不是 Documents 等),但出于某种原因,Command promt 似乎没问题。比较有意思的是:

当我尝试将命令 "//networkpath/home/JDUB~PN6/DOCU~UZL/R/R-34~TN4.0/bin/x64/R" CMD INSTALL -l "H:\Documents\R\R-3.4.0\library" "R:/path/independeR_0.1.8.zip" 直接输入命令提示符时,输出非常相似:

C:\Users\jdubbeldam>"//networkpath/home/JDUB~PN6/DOCU~UZL/R/R-34~TN4.0/b
in/x64/R" CMD INSTALL -l "H:\Documents\R\R-3.4.0\library" "R:/path/independeR_0.1.8.zip"

'\networkpath\home\JDUB~PN6\DOCU~UZL\R\R-34~TN4.0' is not recognized as
 an internal or external command,
operable program or batch file.

不知为什么CMD好像中途切断了命令的路径。我猜这是因为命令太长了。当我尝试相同的命令,但使用 H:/Documents/R/R-3.4.0/bin/x64/R 时,安装进行得很好。

我希望能够从脚本自动安装这个包,所以我想从 R 中解决这个问题。有没有办法让 R 使用较短的 H:/Documents/R/R-3.4.0/bin/x64/R

我设法完成了以下工作。但是,我觉得它非常丑陋,我还是想看看是否可以用其他方式来做。

filename <- paste0("R:/path/independeR_", versions, ".zip")

cmd <- file.path(gsub("//networkpath/home/[[:alnum:]]*/", "H:/",
                      gsub("//networkpath/home/[[:alnum:]]*~[[:alnum:]]*/",
                      "H:/", R.home())), "bin/x64/R")

libname <- gsub("\\\\networkpath/home/[[:alpha:]]*/",
                "H:/", .libPaths()[1])

call <- paste(paste0('"', cmd, '"'), 
              "CMD", 
              "INSTALL", 
              "-l", 
              paste0('"', libname, '"'), 
              "--no-lock",
              paste0('"', filename, '"'), 
              sep = " ")

system(call)

我在更新包时遇到问题,在搜索时我发现有一个已报告的错误会影响从 Windows 10 中的文件获取时间戳: https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=17261

Starting in R 3.4.0, file.info sometimes returns for mtime, atime and ctime for directories. It seems to have something to do with sharing. This affects functions that use file.mtime like update.packages.

Reproduce:

Try file.info() with a random directory. If it returns a legitimate file time, open a windows explorer window and navigate to the directory, then run the call again and it will return s.

In some cases it returns s even if the directory is not open (or in the path of an open explorer window), but this is not consistent.

加上 Tomas Kalibera 的评论:

Thank you for the report, this is a known bug that has been fixed recently in R-devel

我发现当我关闭文件资源管理器时 windows 时间戳工作正常并且没有显示为 NA。
这可能是您的代码无法正常工作的原因。