-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_r_packages.R
54 lines (36 loc) · 1.83 KB
/
install_r_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
48
49
# Create a list of start-up packages
startup_packages <- c("BiocManager", "dplyr", "rvest", "xml2", "yaml")
# Select only the packages that aren't currently installed in the system
install_startup_packages <- startup_packages[which(!startup_packages %in% utils::installed.packages())]
# And finally we install the required packages
for(pkg in install_startup_packages) BiocManager::install(pkg)
# Load packages
library(BiocManager)
library(dplyr)
library(rvest)
library(xml2)
library(yaml)
# Get all available Bioconductor packages
url <- 'https://www.bioconductor.org/packages/release/bioc/'
biocPackages <- url %>%
xml2::read_html() %>%
rvest::html_table() %>%
.[[1]] %>%
dplyr::select(Package) %>%
dplyr::mutate(source = 'BioConductor')
# Read in package dependencies in DESCRIPTION
DESCRIPTION <- yaml::read_yaml("DESCRIPTION")
# Extract all imports packages
required_pkgs <- trimws(strsplit(DESCRIPTION$Imports, ",", fixed=TRUE)[[1]])
# Extract all required bioconductor packages
bioconductor_pkgs <- required_pkgs[which(required_pkgs %in% biocPackages$Package)]
# Select only the packages that aren't currently installed in the system
install_bioconductor_pkgs <- bioconductor_pkgs[which(!bioconductor_pkgs %in% utils::installed.packages())]
# And finally we install the required packages
for(pkg in install_bioconductor_pkgs) BiocManager::install(pkg)
# Extract all required CRAN packages
cran_pkgs <- required_pkgs[which(!required_pkgs %in% bioconductor_pkgs)]
# Select only the packages that aren't currently installed in the system
install_cran_pkgs <- cran_pkgs[which(!cran_pkgs %in% utils::installed.packages())]
# And finally we install the required packages including their dependencies
for(pkg in install_cran_pkgs) utils::install.packages(pkg, dependencies = TRUE, repos='http://cran.rstudio.com/')