[英]How do I compile a R package binary directly from Github?
devtools
軟件包提供了通過install_github
命令從Github安裝軟件包的install_github
。
使用devtools
軟件包中的build
命令,可以從本地文件夾編譯R軟件包二進制文件。
是否還可以使用build
從Github文件夾直接編譯(而不是安裝)R軟件包二進制文件,例如build("https://github.com/user/rpackage")
?
有趣的問題。 我沒有意識到為此目的而構建的功能,但這並不意味着它是不可能的。 我根據學習了一些研究從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
函數build_from_git
將要求您安裝devtools
和git2r
。 此函數將獲取git服務器上托管的R包的url,創建一個臨時目錄,克隆存儲庫,構建該包,將.tar.gz移至工作目錄,然后刪除臨時文件。
請注意,在這項工作中我經常使用:::
,通常不建議這樣做,如Writing R Extensions手冊中所述。 但是,當您需要/想要使用另一個軟件包中的非導出函數時,這是一種合理的編程方法。 參數與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 .")
}
使用示例:
build_from_git(url = "https://github.com/dewittpe/qwraps2.git", progress = interactive())
您應該在工作目錄中看到.tar.gz
文件。
以上工作的會話信息為:
> 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.