-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.R
44 lines (39 loc) · 1.62 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
# Run this script before working with this project. It handles package installation
# and loading, establishes the working directory and sources local functions.
#
# A. check for CRAN available packages - install missing and load all
# B. check for GITHUB available packages - install missing and load all
# C. set the working directory
# D. source each file in subdir 'functions'
#' Here we list the packages required for the project dibdied in to group sources.
#'
#' `cran` packages can be installed with `utils::install.packages()`
#' `github` packages can be installed with `remotes::install_github()`
packages = list(
cran = c("RColorBrewer", "here", "remotes", "tidyr", "readr", "sf", "stars",
"glue", "rnaturalearth", "tidymodels", "dplyr"),
github = c(ecomon = "BigelowLab")
)
#' Installation and loading from CRAN
installed = installed.packages() |> dplyr::as_tibble()
for (package in packages$cran){
if (!package %in% installed$Package) {
cat("installing", package, "from CRAN\n")
install.packages(package)
}
suppressPackageStartupMessages(library(package, character.only = TRUE))
}
#' Installation and loading from github
for (package in names(packages$github)){
pkg = sprintf("%s/%s", packages$github[package], package)
if (!package %in% installed$Package) {
cat("installing", pkg, "from github\n")
remotes::install_github(pkg)
}
suppressPackageStartupMessages(library(package, character.only = TRUE))
}
# define the project root
here::i_am("setup.R")
# source ancillary functions
files = list.files("functions", pattern = "^.*\\.R$", full.names = TRUE)
for (file in files) source(file)