-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_packages.R
50 lines (35 loc) · 1.26 KB
/
get_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
44
45
46
47
# Get all necessary packages across data prep and analysis scripts
# add any packages your scripts require here. Keep in alphabetical order.
loadpacks <- c(
"egg",
"rgdal",
"rgeos",
"sp",
"tidyverse"
)
completed_installs = 0
# Look for an exact match of each package name in the available packages
# If not already download, attempt to download and install
# Provide warnings or errors if any
for(i in loadpacks){
tryCatch({
if(!any(grepl(paste0('^', i, '$'), .packages(all.available=T)))) {
utils::install.packages(i, dependencies = TRUE, repos = "http://cran.us.r-project.org")
completed_installs = completed_installs + 1
}
},
warning = function(warn) {
print(warn)
cat(paste('\n Install exited with warning, probably because ->', i, '<- does not exist in the CRAN repository. Check spelling.'))
},
error = function(error_condition) {
cat(paste('Install exited with an error. \n Check list of packages to make sure all are expected to exist in CRAN reporistory.'))
},
finally = {
NULL
})
}
if(completed_installs > 0) {
cat('Successfully installed', completed_installs, 'packages and dependences for R installed at', Sys.getenv('R_HOME'))
}
rm(i, loadpacks)