我有一堆软件包的源文件及其依赖关系,我想在没有互联网访问的计算机上安装.我想在其他计算机上使用U盘安装所有这些,但某些软件包的安装失败,因为在软件包之前没有安装依赖项.在需要它们的包之前,我如何获得依次安装的顺序?
这是我目前的方法来获取包,它们的依赖关系,并按照正确的顺序来获取它们:
# find the dependencies for the packages I want
# from https://stackoverflow.com/a/15650828/1036500
getPackages
packages
tools::package_dependencies(packs,available.packages(),which=c("Depends","Imports"),recursive=TRUE)
)
packages
packages
}
# packages I want
my_packages
# get names of dependencies and try to get them in the right order,this seems ridiculous...
my_packages_and_dependencies
dependencies_only
deps_of_deps
deps_of_deps_of_deps
my_packages_and_dependencies
# where to keep the source?
local_CRAN
# get them from CRAN,source files
download.packages(pkgs = my_packages_and_dependencies,destdir = local_CRAN,type = "source")
# note that 'tools','methods','utils,'stats',etc. art not on CRAN,but are part of base
# from https://stackoverflow.com/a/10841614/1036500
library(tools)
write_PACKAGES(local_CRAN)
现在假设我在另一台电脑上安装了R和RStudio(和Rtools或Xcode),没有互联网连接,我插上USB棒,打开RProj文件来设置工作目录,并运行这个脚本:
#############################################################
## Install from source (Windows/OSX/Linux)
# What do I want to install?
my_packages_and_dependencies
# where are the source files?
local_CRAN
# scan all packages and get files names of wanted source pckgs
# I've got other things in this dir also
wanted_package_source_filenames
# put them in order to make sure deps go first,room for improvement here...
trims
x1
x2
idx
wanted_package_source_filenames
install.packages(wanted_package_source_filenames,repos = NULL,dependencies = TRUE,contrib.url = local_CRAN,# I thought this would take care of getting dependencies automatically...
type = "source" )
这工作相当不错,但仍然有一些软件包无法安装:
sapply(my_packages_and_dependencies,require,character.only = TRUE)
methods tools bitops stats
TRUE TRUE TRUE TRUE
colorspace graphics tcltk Rcpp
TRUE TRUE TRUE TRUE
digest jsonlite mime RCurl
TRUE TRUE TRUE FALSE
R6 stringr brew grid
TRUE TRUE TRUE TRUE
RColorBrewer dichromat munsell plyr
TRUE TRUE TRUE TRUE
labeling grDevices utils httr
TRUE TRUE TRUE FALSE
memoise whisker evaluate rstudioapi
TRUE TRUE TRUE TRUE
roxygen2 gtable scales proto
TRUE TRUE TRUE TRUE
MASS assertthat magrittr lazyeval
TRUE TRUE TRUE TRUE
DBI stringi yaml htmltools
TRUE TRUE TRUE TRUE
caTools formatR highr markdown
TRUE TRUE TRUE TRUE
gtools devtools ggplot2 dplyr
TRUE FALSE FALSE TRUE
tidyr rmarkdown knitr reshape2
FALSE FALSE TRUE TRUE
gdata
TRUE
Warning messages:
1: In library(package,lib.loc = lib.loc,character.only = TRUE,logical.return = TRUE,:
there is no package called ‘RCurl’
2: In library(package,:
there is no package called ‘httr’
3: In library(package,:
there is no package called ‘devtools’
4: In library(package,:
there is no package called ‘ggplot2’
5: In library(package,:
there is no package called ‘tidyr’
6: In library(package,:
there is no package called ‘rmarkdown’
似乎编织者必须在rmarkdown之前进行,在tidyr和ggplot2之前重塑2等.
必须有一个更简单和更完整的解决方案来获取源文件列表的问题,需要按照正确顺序放置所有依赖关系.最简单的方法是什么(不使用任何贡献的包)?
这是我目前正在开发的系统,我正在使用源版本的软件包来试图为离线计算机(OSX / Linux / Windows)做任何事情做准备:
> sessionInfo()
R version 3.1.2 (2014-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] tcltk grid tools stats graphics
[6] grDevices utils datasets methods base
other attached packages:
[1] gdata_2.13.3 reshape2_1.4.1
[3] knitr_1.9 dplyr_0.4.1
[5] gtools_3.4.1 markdown_0.7.4
[7] highr_0.4 formatR_1.0
[9] caTools_1.17.1 htmltools_0.2.6
[11] yaml_2.1.13 stringi_0.4-1
[13] DBI_0.3.1 lazyeval_0.1.10
[15] magrittr_1.5 assertthat_0.1
[17] proto_0.3-10 scales_0.2.4
[19] gtable_0.1.2 roxygen2_4.1.0
[21] rstudioapi_0.2 evaluate_0.5.5
[23] whisker_0.3-2 memoise_0.2.1
[25] labeling_0.3 plyr_1.8.1
[27] munsell_0.4.2 dichromat_2.0-0
[29] RColorBrewer_1.1-2 brew_1.0-6
[31] stringr_0.6.2 R6_2.0.1
[33] mime_0.2 jsonlite_0.9.14
[35] digest_0.6.8 Rcpp_0.11.4
[37] colorspace_1.2-5 bitops_1.0-6
[39] MASS_7.3-35
loaded via a namespace (and not attached):
[1] parallel_3.1.2
编辑以下Andrie的有用的评论,我已经与miniCRAN一起去,从小插曲中缺少的是如何从本地的repo实际安装包.这是我试过的:
library("miniCRAN")
# Specify list of packages to download
pkgs
# Make list of package URLs
revolution
pkgList
pkgList
# Set location to store source files
local_CRAN
# Make repo for source
makeRepo(pkgList,path = local_CRAN,repos = revolution,type = "source")
# install...
install.packages(pkgs,repos = local_CRAN,# do I really need "file:///"?
dependencies = TRUE,type = "source" )
结果是:
Installing packages into ‘C:/emacs/R/win-library/3.1’
(as ‘lib’ is unspecified)
Warning in install.packages :
unable to access index for repository C:/Users/.../local_CRAN/src/contrib
Warning in install.packages :
packages ‘stringr’,‘devtools’,‘ggplot2’,‘dplyr’,‘tidyr’,‘rmarkdown’,‘knitr’,‘reshape2’,‘gdata’ are not available (for R version 3.1.2)
我在这里缺少什么?
编辑是的,我没有正确使用file:///,它应该是这样的:
install.packages(pkgs,repos = paste0("file:///",local_CRAN),type = "source")
这让我感到震惊,这一切基本上都是按预期的方式工作的.非常感谢.现在我只是想看看:致命错误:curl / curl.h:没有这样的文件或目录,这是阻止RCurl和httr安装.