-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.R
108 lines (90 loc) · 3.38 KB
/
setup.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# Install required packages ----------------------------------------------------
required_packages <- c(
# CRAN packages
"ggplot2", "batchtools", "data.table", "here", "envalysis", "ggpubr",
"ggsci", "fastDummies", "Metrics", "mlr3", "mlr3learners", "mlr3verse",
"ranger", "doParallel", "microbenchmark", "pak", "dplyr", "ISLR2",
"arf", "parallel", "mvtnorm",
# Not CRAN packages
"seqknockoff", "cs", "cpi"
)
if (!all(required_packages %in% rownames(utils::installed.packages()))) {
# Load/install packages
if (interactive()) {
res <- readline(prompt = "Not all packages are installed. Install all required packages? [N/Y]")
} else {
message("Installing required packages!")
res <- "Y"
}
if (tolower(res) == "y") {
pak::pkg_install(c(
"ggplot2", "batchtools", "data.table", "here", "envalysis", "ggpubr",
"ggsci", "fastDummies", "Metrics", "mlr3", "mlr3learners", "mlr3verse",
"ranger", "doParallel", "microbenchmark", "pak", "dplyr", "ISLR2",
"mvtnorm", "parallel",
"bips-hb/arf", "kormama1/seqknockoff",
"christophM/paper_conditional_subgroups",
"bips-hb/cpi"))
} else {
warning("Not all required packages are installed!")
}
} else {
# Check 'cpi' version
if (utils::installed.packages()["cpi", "Version"] < "0.1.5") {
if (interactive()) {
res <- readline(prompt = "'cpi' package >= 0.1.5 is required. Install it? [N/Y]")
} else {
message("Installing correct version of R package 'cpi >= 0.1.5'.")
res <- "Y"
}
if (tolower(res) == "y") {
pak::pkg_install("bips-hb/cpi")
} else {
warning("Not all required packages are installed!")
}
}
# Check 'arf' version
if (utils::installed.packages()["arf", "Version"] < "0.2.2") {
if (interactive()) {
res <- readline(prompt = "'arf' package >= 0.2.2 is required for a fast execution. Install it? [N/Y]")
} else {
message("Installing correct version of R package 'arf >= 0.2.2'.")
res <- "Y"
}
if (tolower(res) == "y") {
pak::pkg_install("bips-hb/arf")
} else {
warning("Not all required packages are installed!")
}
}
message("All required packages are installed!")
}
rm(required_packages)
# Limit number of CPUs ---------------------------------------------------------
# For e.g. XGBoost
Sys.setenv(OMP_NUM_THREADS = 1)
Sys.setenv(OMP_THREAD_LIMIT = 1)
Sys.setenv(MC.CORES = 1)
# Unsure, MKL is an Intel-specific thing
Sys.setenv(MKL_NUM_THREADS = 1)
# Package-specific settings
try(data.table::setDTthreads(1))
try(RhpcBLASctl::blas_set_num_threads(1))
try(RhpcBLASctl::omp_set_num_threads(1))
# Set global ggplot2 theme -----------------------------------------------------
library(ggplot2)
library(envalysis)
theme_set(
theme_publish(base_family = "serif", base_size = 20) +
theme(panel.grid.major.y = element_line("lightgray"),
plot.margin = ggplot2::margin(b = 0))
)
# Create folders for all figures -----------------------------------------------
suppressPackageStartupMessages(library(here))
# For all figures
if (!dir.exists(here("figures"))) dir.create(here("figures"))
# Create subfolder for the appendix
if (!dir.exists(here("figures/appendix"))) dir.create(here("figures/appendix"))
# Create subfolder for plots to be combined to figures
# Create appendix folder
if (!dir.exists(here("figures/tmp_plots"))) dir.create(here("figures/tmp_plots"))