另一种技术是修补devtools
函数,以便它们允许您将stdout
参数传递给system2
. 也不是很优雅,但也许你可以说服包作者以devtools
这种方式进行修改。这是我的补丁build
和install
功能:
library(devtools)
# New functions.
my.install<-function (pkg = ".", reload = TRUE, quick = FALSE, args = NULL, ...)
{
pkg <- as.package(pkg)
message("Installing ", pkg$package)
devtools:::install_deps(pkg)
built_path <- devtools:::build(pkg, tempdir(),...) # pass along the stdout arg
on.exit(unlink(built_path))
opts <- c(paste("--library=", shQuote(.libPaths()[1]), sep = ""),
"--with-keep.source")
if (quick) {
opts <- c(opts, "--no-docs", "--no-multiarch", "--no-demo")
}
opts <- paste(paste(opts, collapse = " "), paste(args, collapse = " "))
devtools:::R(paste("CMD INSTALL ", shQuote(built_path), " ", opts, sep = ""),...) # pass along the stdout arg
if (reload)
devtools:::reload(pkg)
invisible(TRUE)
}
my.build<-function (pkg = ".", path = NULL, binary = FALSE, ...)
{
pkg <- as.package(pkg)
if (is.null(path)) {
path <- dirname(pkg$path)
}
if (binary) {
cmd <- paste("CMD INSTALL ", shQuote(pkg$path), " --build",
sep = "")
ext <- if (.Platform$OS.type == "windows")
"zip"
else "tgz"
}
else {
cmd <- paste("CMD build ", shQuote(pkg$path), " --no-manual --no-resave-data",
sep = "")
ext <- "tar.gz"
}
devtools:::R(cmd, path, ...) # pass along the stdout arg
targz <- paste(pkg$package, "_", pkg$version, ".", ext, sep = "")
file.path(path, targz)
}
# Patch package.
unlockBinding("install", as.environment("package:devtools"))
unlockBinding("build", as.environment("package:devtools"))
assignInNamespace('install', my.install, ns='devtools', envir=as.environment("package:devtools"));
assignInNamespace('build', my.build, ns='devtools', envir=as.environment("package:devtools"));
lockBinding("install", as.environment("package:devtools"))
lockBinding("build", as.environment("package:devtools"))
# Run with no messages.
suppressMessages(install_github('ROAUth','duncantl',stdout=NULL))
本质上,你在三个地方传递了...
,两次在install
函数中,一次在build
函数中。