-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminicran.R
208 lines (169 loc) · 8.13 KB
/
minicran.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
###############################################################
### RUN OUTSIDE OF RADIANT
###############################################################
# installing and loading packages
# repos <- c("file:///Users/vnijs/Desktop/Github/minicran/",
# install.packages("rprojroot")
# install.packages("dplyr")
# install.packages("magrittr")
# install.packages("devtools")
# use locally build miniCRAN so the latest R versions work
# install.packages("miniCRAN")
# See if this can be useful: https://packagemanager.posit.co/client/#/
minicran <- "https://radiant-rstats.github.io/minicran/"
repos <- c(
"https://cloud.r-project.org",
"https://cran.r-project.org",
minicran
)
options(repos = c(CRAN = repos))
# repos = "https://packagemanager.posit.co/cran/2023-08-11"
# options(repos = c(CRAN = "https://packagemanager.posit.co/cran/2023-08-11"))
# install.packages("shiny")
library(devtools)
library(miniCRAN)
source("selMakeRepo.R", local = TRUE)
pth <- rprojroot::find_root(rprojroot::has_file("README.md"))
pkgs <- c(
"radiant", "miniUI", "webshot", "tinytex",
"usethis", "svglite", "ranger", "xgboost",
"pdp", "patchwork", "lobstr", "remotes",
"bslib", "png", "quarto", "vip",
"rlang", "shiny"
)
# check only files that needed updating or adding
# see PR https://github.com/RevolutionAnalytics/miniCRAN/pull/15/files
# not sure if ever merged
# pdb_local <- pkgAvail(repos = repos[1], type="source")
# pdb_remote <- pkgAvail(repos = repos[3:4], type="source")
# pkgList <- pkgDep(pkgs, availPkgs=pdb, repos=revolution, type="source", suggests=FALSE)
pkgs_src <- c(
pkgs, "gitgadget", "ranger", "dbplyr", "DBI", "RSQLite", "RPostgres", "pool",
"odbc", "xgboost", "png", "reticulate", "styler", "caTools",
"tidyverse", "rsample", "vip", "kableExtra", "languageserver", "iml",
"xaringan", "magick", "stringi", "RhpcBLASctl", "V8"
)
# for Karsten
pkgs_karsten <- c(
"ggmap", "leaflet", "tm", "wordcloud", "stm", "Hmisc",
"SDMTools", "gtrendsR", "rgdal"
)
# pkgs_src <- c(
# pkgs_src, "ggmap", "leaflet", "tm", "wordcloud", "rvest", "tidytext",
# "stm", "Hmisc", "SDMTools", "gtrendsR", "rgdal"
# )
# for Ken
# pkgs_src <- c(
# pkgs_src, "stargazer", "lfe"
# )
# for Terry
pkgs_terry <- c("simmer", "simmer.plot", "EnvStats", "ggfortify", "linprog", "lpSolve")
# pkgs_src <- c(
# pkgs_src, "simmer", "simmer.plot", "EnvStats", "ggfortify",
# "linprog", "lpSolve"
# )
## if you have removed a radiant dependency **but**
## the change is not yet on CRAN use the below as repo
# repos <- minicran
# pkgs <- pkgs_src <- c("ranger", "xgboost", "pdp", "patchwork", "clustMixType")
to_remove <- c("Gmedian", "RSpectra")
to_remove <- c(to_remove, pkgs_terry)
to_remove <- c(to_remove, pkgs_karsten)
clean_pkgs <- function(pkl) {
setdiff(pkl, to_remove)
}
# building minicran for source packages
pkgList <- pkgDep(pkgs_src, repos = repos, type = "source", suggests = FALSE)
to_rm <- selMakeRepo(clean_pkgs(pkgList), path = pth, minicran, repos = repos, type = "source")
## only needed when a new major R-version comes out
# download <- makeRepo(pkgs, path = pth, type = "win.binary", Rversion = "4.3")
# download <- makeRepo(pkgs, path = pth, type = "mac.binary", Rversion = "4.3")
# See https://github.com/andrie/miniCRAN/issues/142
# make sure to install miniCRAN from source in the gh/ directory first
# you main also need to edit the internal.R file in miniCRAN_pkg so it
# knows what to do with the newly supported platform
# download <- makeRepo(pkgs, path = pth, type = "mac.binary.big-sur-arm64", Rversion = "4.4")
# download <- makeRepo(pkgs, path = pth, type = "mac.binary.big-sur-x86_64", Rversion = "4.4")
pkgs <- unique(c(pkgs, c("GPArotation", "pdp")))
# pkgs <- "arrow"
# versions <- c("4.0", "4.1", "4.2", "4.3")
versions <- c("4.3", "4.4")
for (ver in versions) {
# ver <- versions
## building minicran for windows binaries
pkgList <- pkgDep(pkgs, repos = repos, type = "win.binary", suggests = FALSE, Rversion = ver)
to_rm <- selMakeRepo(clean_pkgs(pkgList), path = pth, minicran, repos = repos, type = "win.binary", Rversion = ver)
# sapply(setdiff(names(to_rm), "gitgadget"), function(x) unlink(file.path(pth, "bin/windows/contrib", ver, paste0(x, "_*")), force = TRUE))
## building minicran for mac el-capitan binaries
if (ver <= "4.2") {
pkgList <- pkgDep(pkgs, repos = repos, type = "mac.binary", suggests = FALSE, Rversion = ver)
to_rm <- selMakeRepo(clean_pkgs(pkgList), path = pth, minicran, repos = repos, type = "mac.binary", Rversion = ver)
sapply(setdiff(names(to_rm), "gitgadget"), function(x) unlink(file.path(pth, "bin/macosx/contrib", ver, paste0(x, "_*")), force = TRUE))
}
if (ver >= "4.2") {
## building minicran for mac arm64 binaries
pkgList <- pkgDep(pkgs, repos = repos, type = "mac.binary.big-sur-arm64", suggests = FALSE, Rversion = ver)
to_rm <- selMakeRepo(clean_pkgs(pkgList), path = pth, minicran, repos = repos, type = "mac.binary.big-sur-arm64", Rversion = ver)
sapply(setdiff(names(to_rm), "gitgadget"), function(x) unlink(file.path(pth, "bin/macosx/big-sur-arm64/contrib", ver, paste0(x, "_*")), force = TRUE))
}
#
if (ver >= "4.2") {
## building minicran for mac arm64 binaries
pkgList <- pkgDep(pkgs, repos = repos, type = "mac.binary.big-sur-x86_64", suggests = FALSE, Rversion = ver)
to_rm <- selMakeRepo(clean_pkgs(pkgList), path = pth, minicran, repos = repos, type = "mac.binary.big-sur-x86_64", Rversion = ver)
sapply(setdiff(names(to_rm), "gitgadget"), function(x) unlink(file.path(pth, "bin/macosx/big-sur-x86_64/contrib", ver, paste0(x, "_*")), force = TRUE))
}
}
# https://cran.r-project.org/bin/macosx/big-sur-arm64/contrib/4.1/radiant_1.3.2.tgz
# pkgList <- pkgDep("radiant", repos = repos, type = "mac.binary", suggests = FALSE, Rversion = "4.0")
# cat(paste0("pkgs <- c('", paste0(pkgList, collapse = "', '"), "')", collapse = ","), file = "pkgs.R")
# repos <- c(
# "https://cloud.r-project.org",
# "https://cran.r-project.org"
# )
#
# ## building minicran for mac el-capitan binaries
# pkgList <- pkgDep(pkgs, repos = repos, type = "mac.binary", suggests = FALSE, Rversion = ver)
# to_rm <- selMakeRepo(clean_pkgs(pkgList), path = pth, minicran, repos = repos, type = "mac.binary", Rversion = ver)
# sapply(setdiff(names(to_rm), "gitgadget"), function(x) unlink(file.path(pth, "bin/macosx/contrib", ver, paste0(x, "_*")), force = TRUE))
## cleanup
library(dplyr)
library(magrittr)
win_dirs <- list.dirs("bin/windows/contrib")[-1]
mac_dirs <- list.dirs("bin/macosx/el-capitan/contrib")[-1]
mac_dirs <- c(mac_dirs, list.dirs("bin/macosx/contrib")[-1])
mac_dirs <- c(mac_dirs, list.dirs("bin/macosx/big-sur-arm64/contrib")[-1])
mac_dirs <- c(mac_dirs, list.dirs("bin/macosx/big-sur-x86_64/contrib")[-1])
pdirs <- c("src/contrib", win_dirs, mac_dirs)
for (pdir in pdirs) {
print(pdir)
old <- list.files(file.path(pth, pdir)) %>%
data.frame(fn = ., stringsAsFactors = FALSE) %>%
mutate(
pkg_file = fn, pkg_name = strsplit(fn, "_") %>% sapply("[", 1),
pkg_version = strsplit(fn, "_") %>% sapply("[", 2) %>% gsub("(.zip)|(.tar.gz)|(.tgz)", "", .)
) %>%
filter(!is.na(pkg_version))
old <- old[order(old$pkg_name, package_version(old$pkg_version)), ] %>%
group_by(pkg_name) %>%
summarise(old = n(), pkg_file_new = last(pkg_file), pkg_file_old = first(pkg_file)) %>%
filter(old > 1) %T>% print(n = 100)
if (nrow(old) > 0) {
for (pf in old$pkg_file_old) {
unlink(file.path(pth, pdir, pf))
}
}
}
## work-around for https://github.com/ramnathv/htmlwidgets/issues/348
# unlink("src/contrib/htmlwidgets*", force = TRUE)
# curl::curl_download("https://cran.r-project.org/src/contrib/Archive/htmlwidgets/htmlwidgets_1.3.tar.gz", destfile = "src/contrib/htmlwidgets_1.3.tar.gz")
## needed to update PACKAGES after deleting old versions
tools::write_PACKAGES("src/contrib/", type = "source")
sapply(win_dirs, tools::write_PACKAGES, type = "win.binary")
sapply(mac_dirs, tools::write_PACKAGES, type = "mac.binary")
## push to github
rstudioapi::documentSaveAll()
system("git add --all .")
mess <- paste0("update for: ", paste0(pkgs, collapse = ", "), " (", format(Sys.Date(), format = "%m-%d-%Y"), ")")
system(paste0("git commit -m '", mess, "'"))
system("git push")