前言:
在安装的部分发生bug
代码:
libs<-c("xts","TTR")
libs<-c("forestplot")
pkgList<-pkgDep(pkg=libs,availPkgs=aps,repos=repos)
dp<-download.packages(pkgList,"D:/workspace/R/miniCRAN/pgk",type=getOption("pkgType"))
报错:
Error in download.packages(pkgList, "D:/workspace/R/miniCRAN/pgk", type = getOption("pkgType")) : 'destdir'不是目录
解决方式:
问题来源:
dp<-download.packages(pkgList,"D:/workspace/R/miniCRAN/pgk",type=getOption("pkgType"))中我的电脑没有D:/workspace/R/miniCRAN/pgk这个路径,因此我换了个路径,换成
dp<-download.packages(pkgList,"D:/R-studio/RStudio/apps",type=getOption("pkgType"))
已经在下载了:
总结下,使用miniCRAN离线安装R的依赖库的代码:
install.packages("miniCRAN")
library(miniCRAN)
tags <- "xts"
pkgDep(tags, availPkgs = cranJuly2014)
dg <- makeDepGraph(tags, enhances = TRUE, availPkgs = cranJuly2014)
plot(dg, legendPosition = c(-1, 1), vertex.size = 20)
pkgDep(pkg, availPkgs, repos = getOption("repos"), type = "source",
depends = TRUE, suggests = TRUE, enhances = FALSE,
includeBasePkgs = FALSE, Rversion = R.version, quiet = FALSE)
pkgAvail(repos = getOption("repos"), type = "source",
Rversion = R.version, quiet = FALSE)
repos<-getOption("repos")
repos
curl<-contrib.url(repos)
aps<-available.packages(curl)
head(aps)
下面是正式安装依赖包,并把他们存在某个文件夹里面的做法
aps[which(row.names(aps)=='stringdist'),]
libs<-c("stringdist")
pkgList<-pkgDep(pkg=libs,availPkgs=aps,repos=repos)
pkgList
dp<-download.packages(pkgList,"D:/R-studio/RStudio/apps",type=getOption("pkgType"))