我正在尝试运行timeout
,但是R似乎无法正确识别RTools;位于devtools::install_github("gaborcsardi/notifier")
中。
按照https://github.com/r-lib/devtools/issues/1772的说明进行操作后,使用C:\Rtools
和pkgbuild::find_rtools()
的CRAN版本运行devtools
仍然会给我以下错误:
pkgbuild
这是我的Error in rethrow_call(c_processx_exec, command, c(command, args), stdin, :
Command not found @win/processx.c:977
:
session_info()
答案 0 :(得分:3)
实用程序(使用R或其他语言/工具)能够处理简单的文件路径和基于模式的URL(例如https://...
或file:///...
)并不少见,我认为同样可以处理Windows UNC路径(即\\server\share\path
)的工具数量要少得多。虽然我认为R可以很好地找到文件(否则,您只有两个.libPaths()
是UNC共享,您会遇到其他问题),但底层工具(包括gcc
)可能不会
我认为方法是将新软件包安装到不是网络共享的目录中。我还认为,这 可以是一个临时位置,安装后,可以在其中将软件包移动/迁移到网络共享中。
下面的功能可以简化临时目录的创建,将其安装到该目录,然后移至网络共享。 (它实际上并不检查tgt
目录是否为网络共享,而是假定您不需要使用该目录,因为您的第一个库路径是本地的。)
#' Install a package(s) using a temp-local directory
#'
#' On Windows, if '.libPaths()' starts with a UNC network share,
#' package compilation might not work correctly. This function creates
#' a temporary local directory, executes the desired code in 'expr',
#' and moves any new packages into the normal first library path.
#'
#' @param expr expression such as 'install.packages("car")' or
#' 'devtools::install_github(...)'; the expression must natively
#' install into the first of '.libPaths()', but if you try something
#' like 'install.packages(.., lib="some/other/path"), then the
#' temporary libpath will not be used (and may fail)
#' @param tgt character, the directory to move the isntalled
#' package(s)
#' @param cleanup logical, whether to remove the temporary libpath
#' @return nothing
with_local_libpath <- function(expr, tgt = .libPaths()[1], cleanup = TRUE) {
if (length(tgt) > 1) {
warning("'tgt' must be length 1")
tgt <- tgt[[1]]
}
if (length(tgt) < 1 || !dir.exists(tgt)) {
stop("'tgt' must be length 1 and an existing directory")
}
dir.create(tmplib <- tempfile(pattern = "local_libpath_"))
message("Local (temp) libpath: ", sQuote(tmplib))
oldlib <- .libPaths()
.libPaths(c(tmplib, oldlib))
on.exit(.libPaths(oldlib), add = TRUE)
force(expr)
newstuff <- list.files(tmplib, full.names = TRUE)
if (length(newstuff)) {
newdirs <- file.path(oldlib[1], basename(newstuff))
message("New packages found: ", paste(sQuote(basename(newstuff)), collapse = ", "))
message("Moving to: ", sQuote(tgt))
file.copy(newstuff, tgt, recursive = TRUE)
if (cleanup) {
message("Cleaning up")
unlink(tmplib, recursive = TRUE)
}
} else {
message("No new packages found (?)")
}
invisible()
}
我用一些简单的示例对此进行了测试,但没有进行广泛的测试,因此请警告。我没有网络安装的lib-path,因此我将强制使用(到我维护的服务器):
.libPaths(c("\\\\myserver/r2evans/R/win.library/3.5", .libPaths()))
安装失败:
remotes::install_github("gaborcsardi/notifier@d92b1b6")
# Downloading GitHub repo gaborcsardi/notifier@d92b1b6
# v checking for file 'C:\Users\r2\AppData\Local\Temp\RtmpWgKbkW\remotes43cc57193c83\gaborcsardi-notifier-d92b1b6/DESCRIPTION' (377ms)
# - preparing 'notifier':
# v checking DESCRIPTION meta-information
# - checking for LF line-endings in source and make files and shell scripts
# - checking for empty or unneeded directories
# - building 'notifier_1.0.0.tar.gz'
#
# Installing package into '\\myserver/r2evans/R/win.library/3.5'
# (as 'lib' is unspecified)
# * installing *source* package 'notifier' ...
# ** R
# ** inst
# Error in file.create(to[okay]) :
# (converted from warning) cannot create file '\myserver/r2evans/R/win.library/3.5/notifier/R.ico', reason 'No such file or directory'
# * removing '\\myserver/r2evans/R/win.library/3.5/notifier'
# In R CMD INSTALL
# Error: Failed to install 'notifier' from GitHub:
# (converted from warning) installation of package 'C:/Users/r2/AppData/Local/Temp/RtmpWgKbkW/file43cc60c05cc/notifier_1.0.0.tar.gz' had non-zero exit status
(由于https://github.com/gaborcsardi/notifier/issues/22,我选择了特定版本。虽然错误与您的错误不同,但我怀疑失败是由于类似/相关原因。)
成功安装:
with_local_libpath(remotes::install_github("gaborcsardi/notifier@d92b1b6"))
# Local (temp) libpath: 'C:\Users\r2\AppData\Local\Temp\RtmpWgKbkW\local_libpath_43ccbf98e2'
# Downloading GitHub repo gaborcsardi/notifier@d92b1b6
# v checking for file 'C:\Users\r2\AppData\Local\Temp\RtmpWgKbkW\remotes43cc7cb66d1f\gaborcsardi-notifier-d92b1b6/DESCRIPTION' (396ms)
# - preparing 'notifier':
# v checking DESCRIPTION meta-information
# - checking for LF line-endings in source and make files and shell scripts
# - checking for empty or unneeded directories
# - building 'notifier_1.0.0.tar.gz'
#
# Installing package into 'C:/Users/r2/AppData/Local/Temp/RtmpWgKbkW/local_libpath_43ccbf98e2'
# (as 'lib' is unspecified)
# * installing *source* package 'notifier' ...
# ** R
# ** inst
# ** byte-compile and prepare package for lazy loading
# ** help
# *** installing help indices
# converting help for package 'notifier'
# finding HTML links ... done
# notify html
# ** building package indices
# ** testing if installed package can be loaded
# *** arch - i386
# *** arch - x64
# * DONE (notifier)
# In R CMD INSTALL
# New packages found: 'notifier'
# Moving to: '\\myserver/r2evans/R/win.library/3.5'
# Cleaning up
答案 1 :(得分:0)
remotes
中有一个独立模式。此模式消除了对错误的直接原因pkgbuild
的依赖(最终问题在调用链中更深)。
这在remotes
package readme中有记录。
您可以通过{p>强制remotes
使用独立模式
Sys.setenv(R_REMOTES_STANDALONE="true")
找到了该解决方案