もう 1 つの手法は、関数にパッチを適用して、引数を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))
基本的に、関数内で 2 回、関数内で 1...
回の 3 つの場所でを渡します。install
build