-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstartup.R
42 lines (27 loc) · 1.29 KB
/
startup.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
#### LOAD DATA ####
outcome_dat <- read_excel(lang[["loc_outome_table.xlsx"]], sheet = "outcome")
area_dat <- read_excel(lang[["loc_outome_table.xlsx"]], sheet = "area")
# rds_files <- list.files(path = lang[["loc_data_rds"]], pattern = "\\.rds$", full.names = TRUE)
# gradient_dat <- rds_files %>% map_dfr(readRDS)
# technically csv files, not rds.
csv_files <- list.files(path = lang[["loc_data_rds"]], pattern = "\\.csv$", full.names = TRUE)
# gradient_dat <- csv_files %>% map_dfr(fread)
read_and_cast_csv <- function(file) {
dt <- fread(file)
dt[, N := as.numeric(N)]
dt[, parents_income := as.numeric(parents_income)]
dt[, mean := as.numeric(mean)]
# Ensure all other columns are of type character
dt <- dt %>% mutate(across(-c(N, mean, parents_income), as.character))
return(dt)
}
cols_fact <- c("geografie", "geslacht", "migratieachtergrond", "huishouden", "bins", "opleiding_ouders", "uitkomst",
"type")
gradient_dat <- csv_files %>% map_dfr(~read_and_cast_csv(.x)) %>%
mutate_at(cols_fact, factor)
# txt file for README in download button for data and fig
# temp_txt <- paste(readLines("./data/README.txt"))
temp_txt <- paste0(
lang[["download_readme_title"]], "\n",
"================================================================================\n"
)