[英]How do I compile a R package binary directly from Github?
The devtools
package offers the possiblity to install a package right from Github through the install_github
command. devtools
软件包提供了通过install_github
命令从Github安装软件包的install_github
。
Using the build
command in the devtools
package one can compile a R package binary from a local folder. 使用
devtools
软件包中的build
命令,可以从本地文件夹编译R软件包二进制文件。
Is it also possible to use build
to directly compile (not install) a R package binary from a Github folder, ie something like build("https://github.com/user/rpackage")
? 是否还可以使用
build
从Github文件夹直接编译(而不是安装)R软件包二进制文件,例如build("https://github.com/user/rpackage")
?
Interesting question. 有趣的问题。 I'm unaware of a function that has been built for this purpose but that doesn't mean it is not possible.
我没有意识到为此目的而构建的功能,但这并不意味着它是不可能的。 I wrote a function for this based on what I learned for studying several non-exported functions from the
devtools
package, specifically, 我根据学习了一些研究从
devtools
软件包中导出的未导出函数的知识后,为此编写了一个函数,具体来说,
# devtools:::git_remote
# devtools:::remote
# devtools:::install_remotes
# devtools:::try_install_remote
# devtools:::install_remote
# devtools:::install
# devtools:::R
# devtools:::remote_download.git_remote
The function build_from_git
will require that you have devtools
and git2r
installed. 函数
build_from_git
将要求您安装devtools
和git2r
。 This function will take the url for a R package hosted on a git server, create a temp directory, clone the repo, build the package, move the .tar.gz to the working directory, and then delete the temporary files. 此函数将获取git服务器上托管的R包的url,创建一个临时目录,克隆存储库,构建该包,将.tar.gz移至工作目录,然后删除临时文件。
Note that I'm using :::
often in this work, which is generally not recommended as noted in the Writing R Extensions manual. 请注意,在这项工作中我经常使用
:::
,通常不建议这样做,如Writing R Extensions手册中所述。 However, when you need/want to use non-exported functions from another package this is a reasonable programming approach. 但是,当您需要/想要使用另一个软件包中的非导出函数时,这是一种合理的编程方法。 The arguments are the same as from
devtools::install_git
. 参数与
devtools::install_git
的参数相同。
build_from_git <- function(url, subdir = NULL, branch = NULL, credentials = NULL, progress = interactive()) {
grmt <- devtools:::git_remote(url, subdir = subdir, branch = branch, credentials = NULL)
bundle <- "__temp__"
git2r::clone(grmt$url, bundle, credentials = grmt$credentials, progress = progress)
if (!is.null(grmt$branch)) {
r <- git2r::repository(bundle)
git2r::checkout(r, grmt$branch)
}
on.exit(unlink(bundle, recursive = TRUE), add = TRUE)
sourcepkg <- devtools::as.package(devtools:::source_pkg(bundle, subdir = grmt$subdir))
on.exit(unlink(sourcepkg, recursive = TRUE), add = TRUE)
devtools:::R("CMD build . ", path = "__temp__")
system("mv __temp__/*.tar.gz .")
}
Example use: 使用示例:
build_from_git(url = "https://github.com/dewittpe/qwraps2.git", progress = interactive())
You should see the .tar.gz
file in your working directory. 您应该在工作目录中看到
.tar.gz
文件。
The session info for the work done above is: 以上工作的会话信息为:
> sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 9 (stretch)
Matrix products: default
BLAS: /usr/lib/openblas-base/libblas.so.3
LAPACK: /usr/lib/libopenblasp-r0.2.19.so
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.4.1 withr_1.0.2 memoise_1.1.0 git2r_0.19.0
[5] digest_0.6.12 devtools_1.13.2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.