-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.R
186 lines (160 loc) · 6.61 KB
/
update.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
options(HTTPUserAgent = sprintf("R/%s R (%s)", getRversion(), paste(getRversion(), R.version$platform, R.version$arch, R.version$os)))
repos = c(
RSM = "https://rsm-compute-01.ucsd.edu:4242/rsm-msba/__linux__/focal/latest",
RSPM = "https://packagemanager.rstudio.com/all/__linux__/focal/latest",
MINICRAN = "https://radiant-rstats.github.io/minicran/",
CRAN = "https://cloud.r-project.org"
)
os <- Sys.info()["sysname"]
repos <- if (os == "Linux") repos else repos[c(3, 4, 1, 2)]
options(repos = repos)
## install script for R(adiant) @ Rady School of Management (MBA and MSBA)
build <- function(type = ifelse(os == "Linux", "source", "binary")) {
install.packages("remotes", dependencies = FALSE, type = type)
remotes::install_github("radiant-rstats/radiant.update", upgrade = "never")
## get list of packages to update
op <- old.packages(lib.loc = .libPaths()[1])
## keep track of any package install issues (windoze)
err_packages <- c()
## keep track of loaded name space on Windoze
lns <- loadedNamespaces()
if (length(op) > 0) {
op <- op[,"Package"]
os <- Sys.info()["sysname"]
if (os == "Windows") {
if ("yaml" %in% op && "yaml" %in% lns) {
op <- op[-which(op == "yaml")]
err_packages <- "yaml"
}
}
}
## installs and unpacks one at time
## seems more robust than update.packages
if (length(op) > 0) {
cat("\n#################################################\n")
cat("Updating previously installed packages")
cat("\n#################################################\n\n")
for (p in op) {
if (p %in% lns) {
err <- try(unloadNamespace(p), silent = TRUE)
if (inherits(err, "try-error")) {
cat("** There might be an issue updating package", p, "**\n")
cat(err, "\n")
err_packages <- c(err_packages, p)
}
if (p == "yaml") loadNamespace("yaml")
}
## sometimes trying to install dependencies (e.g., Matrix) causes problems
## all deps should already be available in op by using the minicran package
## and all packages will be installed 1-by-1
update.packages(
lib.loc = .libPaths()[1], ask = FALSE, oldPkgs = p, dependencies = FALSE,
type = type
)
}
}
## additional packages ... not required but useful
np <- new.packages(lib.loc = .libPaths()[1], ask = FALSE)
if (length(np) > 0) {
cat("\n#################################################\n")
cat("Installing new packages")
cat("\n#################################################\n\n")
for (p in np) {
if (p %in% lns) {
err <- try(unloadNamespace(p), silent = TRUE)
if (inherits(err, "try-error")) {
cat("** There might be an issue installing package", p, "**\n")
cat(err, "\n")
err_packages <- c(err_packages, p)
}
if (p == "yaml") loadNamespace("yaml")
}
## sometimes trying to install dependencies (e.g., Matrix) causes problems
## all deps should already be available in op by using the minicran package
## and all packages will be installed 1-by-1
install.packages(p, dependencies = FALSE, type = type)
}
}
# see https://github.com/wch/webshot/issues/25#event-740360519
if (is.null(webshot:::find_phantom())) {
webshot::install_phantomjs()
}
if (length(err_packages) == 0 | identical(err_packages, "yaml")) {
message('\nTesting if Radiant can be loaded ...')
success <- "\nRadiant update successfully completed\n"
failure <- "\nRadiant update attempt was unsuccessful. Please copy the source command below, restart R(studio), and then paste the command into the R(studio) console and press return. If the update is still not successful, please send an email to [email protected] with screen shots of the output shown in R(studio).\n\nsource('https://raw.githubusercontent.com/radiant-rstats/minicran/gh-pages/update.R')\n\n-------------------------------------------------------------------------------------\n"
os <- Sys.info()["sysname"]
if (os == "Windows") {
if (rstudioapi::versionInfo()$version >= "1.1.383") {
ret <- suppressPackageStartupMessages(require("radiant"))
if (ret) {
message(success)
} else {
message(failure)
}
} else {
## require(...) reliably causes Rstudio crash (1.1.359)
cmd <- "source('https://raw.githubusercontent.com/radiant-rstats/minicran/gh-pages/win_check.R')"
ret <- .rs.restartR(cmd)
}
} else {
ret <- suppressPackageStartupMessages(require("radiant"))
if (ret) {
message(success)
} else {
message(failure)
}
}
}
return(unique(err_packages))
}
updater <- function() {
ul <- try(
sapply(
c("radiant", "radiant.multivariate", "radiant.model", "radiant.basics", "radiant.design", "radiant.data"),
unloadNamespace),
silent = TRUE
)
rv <- R.Version()
rv <- paste(rv$major, rv$minor, sep = ".")
if (rv < "3.6") {
message("Radiant requires R-3.6.0 or later. Please install the latest\nversion of R from https://cloud.r-project.org/")
} else {
os <- Sys.info()["sysname"]
if (os == "Windows") {
build()
} else if (os == "Darwin") {
resp <- system("sw_vers -productVersion", intern = TRUE)
if (resp < "10.9") {
message("Your version of macOS is no longer supported by R. You will need to upgrade the OS before proceeding\n\n")
} else {
build()
}
} else {
build()
}
}
}
err <- updater()
err <- err[!err %in% installed.packages()]
## https://stackoverflow.com/questions/50422627/different-results-from-deparse-in-r-3-4-4-and-r-3-5
dctrl <- if (getRversion() > "3.4.4") c("keepNA", "niceNames") else "keepNA"
if (length(err) > 0) {
cat("\n\n###############################################################\n\n")
cat(" Some packages were not successfully installed or updated\n\n")
cat(" Restart R(studio) and use the command(s) below to install these packages:\n\n")
rerr <- grepl("^radiant", err)
if (sum(rerr) > 0) {
err_radiant <- paste0(deparse(err[rerr], control = dctrl, width.cutoff = 500L), collapse = "")
err <- paste0(deparse(err[!rerr], control = dctrl, width.cutoff = 500L), collapse = "")
if (length(err) > 0) {
cat(paste0(" install.packages(", err, ")\n"))
}
cat(paste0(" install.packages(", err_radiant, ")\n"))
} else {
err <- paste0(deparse(err, control = dctrl, width.cutoff = 500L), collapse = "")
cat(paste0(" install.packages(", err, ")\n"))
}
cat("\n###############################################################\n\n")
}
rm(updater, build, err)