-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path00_setup.R
94 lines (52 loc) · 1.69 KB
/
00_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
set.seed(42)
library(purrr)
library(dplyr)
library(tidyr)
library(readr)
library(forcats)
library(stringr)
library(ggplot2)
library(viridis)
library(marlin)
library(here)
library(furrr)
library(gamm4)
library(lme4)
library(patchwork)
library(ggrepel)
library(ggdist)
library(rmarkdown)
library(extrafont)
options(dplyr.summarise.inform = FALSE)
foos <- list.files(here("functions"))
walk(foos, ~ source(here("functions", .x)))
if (Sys.getenv("RUN_NAME") == ''){
run_name <- "v1.1"
} else {
run_name <- Sys.getenv("RUN_NAME")
}
results_path <- here("results", run_name)
if (!dir.exists(results_path)){
dir.create(results_path, recursive = TRUE)
dir.create(file.path(results_path,"sims"))
}
run_coral_example <- TRUE
run_blue_water_example <- TRUE
theme_set(marlin::theme_marlin(base_size = 12))
# load data ---------------------------------------------------------------
if (!file.exists(here("data","marlin-inputs.xlsx"))){
download.file("https://figshare.com/ndownloader/files/38766174", destfile = "data.zip", overwrite = TRUE,
mode = "wb")
unzip("data.zip")
file.remove("data.zip")
}
marlin_inputs <- readxl::read_xlsx(here("data","marlin-inputs.xlsx"), sheet = "inputs",na = c("NA",""))
if (!file.exists(here("data","sci_to_com.csv"))){
sci_to_com <- taxize::sci2comm(unique(marlin_inputs$scientific_name),simplify= TRUE,db='ncbi') %>%
bind_rows(.id = "critter") %>%
pivot_longer(everything(),names_to = "critter",values_to = "common_name") %>%
mutate(common_name = stringr::str_to_title(common_name))
write_csv(sci_to_com, file = here("data","sci_to_com.csv"))
} else{
sci_to_com <- read_csv(file = here("data","sci_to_com.csv"))
}