-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_packages.R
More file actions
34 lines (33 loc) · 1.23 KB
/
install_packages.R
File metadata and controls
34 lines (33 loc) · 1.23 KB
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
#' @title Function to install sets of R packages
#'
#' The `install_packages()` function installs sets of R packages defined in
#' (tab separated) text files.
#'
#' @param path `character(1)` with the path to the directory containing the txt
#' files from which package lists should be read.
#'
#' @param files optional `character` vector with the actual file names from
#' which to read package definition.
#'
#' @export
install_packages <- function(path = ".", files = dir(path, pattern = ".txt$")) {
if (!length(files))
stop("No files provided or found in the specified path")
pkg <- character()
for (i in seq_along(files)) {
message("Installing packages defined in \"", files[i], "\"")
pkgs <- read.table(files[i])[, 1L]
BiocManager::install(pkgs, ask = FALSE)
pkg <- c(pkg, pkgs)
}
pkgi <- installed.packages()[, "Package"]
pkg <- vapply(strsplit(pkg, "/"), function(z) z[length(z)], NA_character_)
pkgn <- pkg[!pkg %in% pkgi]
if (length(pkgn)) {
message("\n\nThe following packages failed to install:")
message(paste0(pkgn, collapse = "\n"))
message("You might want to install them manually\n\n")
}
}
## RUn the installation.
install_packages()