-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path00_install.R
23 lines (18 loc) · 1.05 KB
/
00_install.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# ------------------------------------------------------------------------------
#' Install needed packages
# ------------------------------------------------------------------------------
# Get list of needed packages
pkgs_used <- read.csv("logs/pkgs_used.csv", stringsAsFactors = FALSE)
installed <- sapply(pkgs_used$packages, require, character.only = TRUE,
quietly = TRUE)
to_install <- pkgs_used$packages[!installed]
# Install needed packages
install.packages(to_install, repos = "http://cloud.r-project.org")
# Comparing installed versions
sapply(pkgs_used$packages, require, character.only = TRUE, quietly = TRUE) # run this again to load pkgs
version_comp <- unlist(lapply(pkgs_used$packages, function(x) as.character(packageVersion(x))))
version_installed <- gsub("-", ".", as.character(pkgs_used$version))
# If any installed are older, update these
to_update <- pkgs_used$pkgs[version_comp < version_installed]
# Run the next line if you want to update installed packages
# update.packages(to_update, repos = "http://cloud.r-project.org")