forked from ashattock/dynamice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dependencies.R
88 lines (65 loc) · 2.55 KB
/
dependencies.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
###########################################################
# DEPENDENCIES
#
# Deal with all package dependencies in one place.
#
###########################################################
# ---- R version check ----
# R versions for which this project has been tested and is stable
stable_versions = "4.3.0"
# R versions for which this project is stable (as a string)
stable_str = paste(stable_versions, collapse = ", ")
# Get details of R version currently running
version_info = R.Version()
# Construct version number from list details
version_num = paste0(version_info$major, ".", version_info$minor)
# Throw an error if this R version is unsuitable
if (!version_num %in% stable_versions)
stop("This software is stable with R version(s): ", stable_str,
" (currently running ", version_num, ")")
# Clear global environment
rm(list = ls())
# ---- Define packages ----
message("* Installing required packages")
# Complete list of all R packages required for this project
packages = c(
"tidyverse", # Includes ggplot2, dplyr, tidyr (www.tidyverse.org/packages/)
"data.table", # Next generation dataframes
"Rcpp", # C++ integration
"magrittr", # Additional pipe operators, such as %<>%
"wrapr", # Convenience functions (eg qc)
"countrycode", # Country name <-> code transformation
"readxl", # Data loading functionality
"lubridate", # Data formatting functionality
"naniar", # Data formatting functionality
"ggpubr", # Plotting functionality
"scales", # Plotting functionality
"pals", # Colour palettes
"colorspace") # Colour palettes
# ---- Install and/or load R packages with pacman ----
# Check whether pacman itself has been installed
pacman_installed = "pacman" %in% rownames(installed.packages())
# If not, install it
if (!pacman_installed)
install.packages("pacman")
# Load pacman
library(pacman)
# Load all required packages, installing them if required
pacman::p_load(char = packages)
# ---- Source files ----
# Scripts that should bot be sourced
no_src = c("launch.R", "dependencies.R", "submit.R")
# All R files, and those to source
all_files = list.files(pattern = ".+\\.R$")
src_files = setdiff(all_files, no_src)
# Source each of these files
for (file in src_files)
source(file)
# Source all C++ files
all_cpp_files = list.files(pattern = ".+\\.cpp$")
for (file in all_cpp_files)
sourceCpp(file)
# ---- Clean up ----
# Tidy up console after package loading
if (interactive()) clf() # Close figures
if (interactive()) clc() # Clear console