Bläddra i källkod

fix a bug in report processing

transposing the list would silently drop list elements
main
Garrick Aden-Buie 2 år sedan
förälder
incheckning
7a2cef064a
Ingen känd nyckel hittad för denna signaturen i databasen
3 ändrade filer med 23 tillägg och 6 borttagningar
  1. +17
    -0
      process/R/list_transpose_bind.R
  2. +1
    -2
      process/R/read_report_file.R
  3. +5
    -4
      process/R/report_path_info.R

+ 17
- 0
process/R/list_transpose_bind.R Visa fil

@@ -0,0 +1,17 @@
list_transpose_bind <- function(x) {
purrr::reduce(x, list_transpose_bind_impl)
}

list_transpose_bind_impl <- function(x, acc) {
if (!length(x)) return(acc)

for (name in names(x)) {
if (!name %in% names(x)) {
acc[[name]] <- x[[name]]
} else {
acc[[name]] <- dplyr::bind_rows(acc[[name]], x[[name]])
}
}

acc
}

+ 1
- 2
process/R/read_report_file.R Visa fil

@@ -105,8 +105,7 @@ process_report_export <- function(dir_sboe_id, report_list = tar_read(report_lis

info$path |>
map(read_report_file) |>
transpose() |>
map(list_rbind) |>
list_transpose_bind() |>
map(report_data_set_column_type)
}


+ 5
- 4
process/R/report_path_info.R Visa fil

@@ -1,12 +1,13 @@
report_path_info <- function(report_path) {
# data-raw/reports/{sboe_id}/all/{report_id}_{received_date}.txt
report_path <- fs::path_abs(report_path)
x <- fs::path_rel(report_path, here::here("..", "data-raw", "reports"))
x <- fs::path_abs(report_path)
x <- map(x, path_split) |> list_flatten()

idx_reports <- map_int(x, \(x) which(x == "reports"))

tibble(
sboe_id = map_vec(x, \(x) x[1]),
report_id = map_int(x, \(x) as.integer(strsplit(x[3], "_")[[1]][1])),
sboe_id = map2_vec(x, idx_reports, \(x, i) x[i + 1]),
report_id = map2_int(x, idx_reports, \(x, i) as.integer(strsplit(x[i + 3], "_")[[1]][1])),
)
}


Laddar…
Avbryt
Spara