Commit f285bf42 authored by LDalby's avatar LDalby
Browse files

Use map and unnest

parent 0d8193e9
......@@ -23,29 +23,37 @@ plan(multiprocess) # to run in parallel future_map in parallel.
suffix <- stringr::str_pad(as.character(1:npar), width = 2, pad = "0")
path(path_to_dirs, glue::glue("WD{suffix}"), "Results", file_name) %>%
future_map(data.table::fread) %>%
data.table::rbindlist() %>%
data.table::setnames(c("season", "day", "pinkfoot", "pinkfoot_dist",
tibble::tibble(file_name = .,
wd = glue::glue("WD{suffix}")) %>%
dplyr::mutate(file_contents = future_map(file_name, ~data.table::fread(file = .))) %>%
tidyr::unnest() %>%
purrr::set_names(c("file_name", "wd", "season", "day", "pinkfoot", "pinkfoot_dist",
"barnacle", "barnacle_dist", "greylag", "greylag_dist",
"grain", "maize", "polyref", "param", "value")) -> all_res
grain_file_name <- "scenario-grain-distributions.txt"
path(path_to_dirs, glue::glue("WD{suffix}"), "Results", grain_file_name) %>%
future_map(data.table::fread) %>%
data.table::rbindlist() %>%
data.table::setnames(c("season", "grain_dist", "param", "value")) -> all_grain
tibble::tibble(file_name = .,
wd = glue::glue("WD{suffix}")) %>%
dplyr::mutate(file_contents = future_map(file_name, ~data.table::fread(file = .))) %>%
tidyr::unnest() %>%
purrr::set_names(c("season", "grain_dist", "param", "value")) -> all_grain
rotation_file_name <- "scenario-rotations.txt"
path(path_to_dirs, glue::glue("WD{suffix}"), rotation_file_name) %>%
future_map(data.table::fread) %>%
data.table::rbindlist() %>%
data.table::setnames(c("wd", "rotation")) -> all_rotation
tibble::tibble(file_name = .,
wd = glue::glue("WD{suffix}")) %>%
dplyr::mutate(file_contents = future_map(file_name, ~data.table::fread(file = .))) %>%
tidyr::unnest() %>%
purrr::set_names(c("wd", "rotation")) -> all_rotation
numbers_file_name <- "scenario-goose-numbers.txt"
path(path_to_dirs, glue::glue("WD{suffix}"), "Results", numbers_file_name) %>%
future_map(data.table::fread) %>%
data.table::rbindlist() %>%
data.table::setnames(c("season", "day", "pf_families", "pf_non_breeders", "bn_families",
tibble::tibble(file_name = .,
wd = glue::glue("WD{suffix}")) %>%
dplyr::mutate(file_contents = future_map(file_name, ~data.table::fread(file = .))) %>%
tidyr::unnest() %>%
purrr::set_names(c("season", "day", "pf_families", "pf_non_breeders", "bn_families",
"bn_non_breeders", "gl_families", "gl_non_breeders", "snow_depth",
"param", "value")) -> all_numbers
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment