「インターネットに接続できない環境があって、そこにCRANパッケージをインストールしたい時にどうしたらいいんだっけ?」と思って調べたら、miniCRANに辿り着いたので、メモを残しておく。
Disclaimer
公式ドキュメントとブログに書かれてることしかやってないです。違いは国内のミラーを使っているくらい?
- https://cran.r-project.org/web/packages/miniCRAN/vignettes/miniCRAN-introduction.html
- https://kbroman.org/blog/2017/05/23/minicran/
インストール
install.packages("miniCRAN")
レポジトリをつくる
library(miniCRAN)
# Use mirror in Japan
repo <- c(CRAN = "https://cran.ism.ac.jp/")
pkgs <- c("ggplot2")
pkgList <- pkgDep(pkgs, repos = repo, type = "source", suggests = FALSE)
pkgList
# Create temporary folder for miniCRAN
dir.create(pth <- file.path(tempdir(), "miniCRAN"))
# Make repo for source, win.binary and mac.binary.el-capitan
makeRepo(pkgList, path=pth, repos=repo, type=c("source", "win.binary", "mac.binary.el-capitan"))
# List all files in miniCRAN
list.files(pth, recursive = TRUE, full.names = FALSE)
# Check for available packages
pkgAvail(repos = pth, type="mac.binary.el-capitan")
ローカルからインストールする
install.packages(pkgs, repos=paste0("file:///", pth), type = "source")