-
-
Save sooheang/97ece8ba93dcf92a022541fa882db579 to your computer and use it in GitHub Desktop.
Use miniCRAN for local R package install
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# miniCRAN - | |
# https://cran.r-project.org/web/packages/miniCRAN/vignettes/miniCRAN-introduction.html | |
library(miniCRAN) | |
library(magrittr) | |
# Specify list of packages to download | |
pkgs <- c( | |
"miniCRAN", | |
"futile.logger", | |
"magrittr", | |
"data.table", | |
"readr", | |
"readxl", | |
"DBI", | |
"tidyverse", | |
"qualV", | |
"stringr", | |
"fossil", | |
"leaflet", | |
"ggmap", | |
"geosphere", | |
"rgeos", | |
"factoextra", | |
"ggdendro", | |
"readr", | |
"ggplot2", | |
"rgdal", | |
"readxl", | |
"RSQLite", | |
"proj4", | |
"shiny", | |
"flexdashboard", | |
"rpart", "rpart.plot", | |
"party", | |
"caret", | |
"randomForest", | |
"forcats", | |
"forecast", | |
"broom", | |
"rattle", | |
"tidytext", | |
"jiebaR", | |
"ldatuning", | |
"viridis", | |
"lda", | |
"qualV", | |
"arules", "arulesViz", "arulesCBA", "arulesSequences", | |
"ggnetwork", | |
"recommenderlab", | |
"odbc", | |
"ModelMetrics", | |
"onehot", | |
"xgboost", | |
"Information", "InformationValue", | |
"precrec", | |
"tictoc", | |
"OutlierDC", | |
"OutlierDM", | |
"rmarkdown", | |
"packrat", | |
"testthat", | |
"purr", | |
"plumber", | |
"feather" | |
) | |
# Define the package source: a CRAN mirror | |
CRAN_mirror <- c(CRAN = "http://cloud.r-project.org/") | |
pkgList <- pkgDep(pkgs, | |
repos = CRAN_mirror, | |
type = "win.binary", | |
suggests = FALSE) | |
ml_pkg <- pkgDep(c("caret", "dplyr"), | |
repos = CRAN_mirror, type = "win.binary", | |
suggests = TRUE) | |
pkgList <- pkgList %>% union(ml_pkg) | |
local_path <- normalizePath("~/miniCRAN", winslash = "/") | |
# Make repo for source and win.binary ------------------------------------- | |
# dir.create(local_path, showWarnings = F) | |
# makeRepo(pkgList, path=local_path, repos=CRAN_mirror, | |
# type=c("win.binary", "source")) | |
# Check for available packages | |
pdb <- pkgAvail(repos = local_path, type = "win.binary") | |
pdb[, c(1:2)] | |
# Add new packages -------------------------------------------------------- | |
new_pkg <- setdiff(pkgList, pkgAvail(repos = local_path, type = "win.binary", Rversion = "3.5")) | |
if (length(new_pkg)) { | |
addPackage( | |
new_pkg, | |
path = local_path, | |
repos = CRAN_mirror, | |
type = c("win.binary"), | |
deps = FALSE | |
) | |
message("New pkgs:\n", new_pkg) | |
} else { | |
message("No new package to add to miniCRAN") | |
} | |
# Add github packages ----------------------------------------------------- | |
# https://github.com/RevolutionAnalytics/miniCRAN/issues/50 | |
# see devtools::install_remote() to see how the package source bundle is | |
# downloaded. from there, #23's addLocalPackage can take over | |
# addLocalPackage("wordVectors-master", pkgPath="../Downloads", path = local_path, | |
# type="win.binary", build = TRUE) | |
# Update available packages ----------------------------------------------- | |
updatePackages(path = local_path, | |
repos = CRAN_mirror, | |
type = c("win.binary"), | |
ask = FALSE) # should need update |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# uri <- paste0("file:///", "path/to/miniCRAN") | |
# options(repos = c(CRAN = uri)) | |
# gertOption("repos") | |
available.packages(type = "win.binary") | |
install.packages("xxxx", type = "win.binary") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set miniCRAN dir as default CRAN URI | |
local({ | |
uri <- paste0("file:///", normalizePath("~/miniCRAN", winslash="/")) | |
options(repos = c(CRAN = uri)) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment