-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_packages.R
43 lines (40 loc) · 1.12 KB
/
install_packages.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
# define package names and versions
package_versions <- list(
ggplot2 = NULL,
readxl = NULL,
dplyr = "1.1.2",
tidyr = "1.3.0",
lubridate = "1.9.2",
scales = "1.2.1",
data.table = "1.14.8",
zoo = "1.8-12",
leafpop = "0.1.0",
INLA = "21.2.23",
openxlsx = "4.2.5.2",
Dict = "0.1.0",
sp = "1.6-0",
sf = "1.0-12",
terra = NULL,
spdep = "1.2-8",
sfdep = "0.2.3",
stringi = "1.7.12",
reshape2 = "1.4.4",
tmap = "3.3.4"
)
# install packages not yet installed
install_specific_version <- function(package, version) {
if (!package %in% rownames(installed.packages())) {
install.packages(package, repos = NULL, type = "source")
}
if (!is.null(version) && packageVersion(package) != version) {
install.packages(package, repos = NULL, type = "source", version = version)
}
}
# install specific versions or latest versions
invisible(lapply(names(package_versions), function(pkg) install_specific_version(pkg, package_versions[[pkg]])))
# load packages
invisible(lapply(names(package_versions), function(pkg) {
if (!is.null(package_versions[[pkg]])) {
library(pkg, character.only = TRUE)
}
}))