|
|
|
|
|
|
|
|
info <- report_path_info(report_path) |
|
|
info <- report_path_info(report_path) |
|
|
lines <- brio::read_file(report_path) |
|
|
lines <- brio::read_file(report_path) |
|
|
|
|
|
|
|
|
sections_raw <- strsplit(lines, "\n\r\n")[[1]] |
|
|
|
|
|
|
|
|
sections_raw <- strsplit(lines, "\n\r?\n")[[1]] |
|
|
sections_raw <- trimws(sections_raw) |
|
|
sections_raw <- trimws(sections_raw) |
|
|
sections_raw <- sections_raw[nzchar(sections_raw)] |
|
|
sections_raw <- sections_raw[nzchar(sections_raw)] |
|
|
|
|
|
|
|
|
sections <- lapply(sections_raw, read_report_section, info = info) |
|
|
|
|
|
|
|
|
sections <- lapply(sections_raw, read_report_section, info = info, report_path = report_path) |
|
|
|
|
|
|
|
|
purrr::flatten(sections) |
|
|
purrr::flatten(sections) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
read_report_section <- function(section, info) { |
|
|
|
|
|
|
|
|
read_report_section <- function(section, info, report_path) { |
|
|
if (!grepl("^[A-Z ]+\n", section)) { |
|
|
if (!grepl("^[A-Z ]+\n", section)) { |
|
|
browser() |
|
|
|
|
|
|
|
|
# browser() |
|
|
stop("Expected a title at the start of a section") |
|
|
stop("Expected a title at the start of a section") |
|
|
} |
|
|
} |
|
|
title <- snakecase::to_snake_case(sub("\n.+", "", section)) |
|
|
title <- snakecase::to_snake_case(sub("\n.+", "", section)) |
|
|
|
|
|
|
|
|
body <- sub("^[A-Z ]+\n", "", section) |
|
|
body <- sub("^[A-Z ]+\n", "", section) |
|
|
header <- strsplit(body, "\n")[[1]][[1]] |
|
|
header <- strsplit(body, "\n")[[1]][[1]] |
|
|
# trailing commas should be on the previous line |
|
|
# trailing commas should be on the previous line |
|
|
body <- gsub("(\\w)\n,", "\\1,", body) |
|
|
|
|
|
|
|
|
body <- gsub("(\\w) ?\n,,,", "\\1,,,", body) |
|
|
# remove header |
|
|
# remove header |
|
|
body <- trimws(sub(header, "", body, fixed = TRUE)) |
|
|
body <- trimws(sub(header, "", body, fixed = TRUE)) |
|
|
body <- gsub("([^,]+ )\n([^,]+)", "\\1\\2", body) |
|
|
body <- gsub("([^,]+ )\n([^,]+)", "\\1\\2", body) |
|
|
|
|
|
|
|
|
# browser(expr = title == "cover" && ncol(data) != 16) |
|
|
# browser(expr = title == "cover" && ncol(data) != 16) |
|
|
|
|
|
|
|
|
if (nrow(problems(data))) { |
|
|
if (nrow(problems(data))) { |
|
|
|
|
|
browser() |
|
|
problems <- problems(data) |
|
|
problems <- problems(data) |
|
|
problems$file <- report_path |
|
|
problems$file <- report_path |
|
|
problems$section <- title |
|
|
problems$section <- title |
|
|
|
|
|
path <- here::here("data-raw", "reports", "read-raw-reports-problems.csv") |
|
|
problems |> |
|
|
problems |> |
|
|
write_csv( |
|
|
|
|
|
here::here("data-raw", "reports", "read-raw-reports-problems.csv"), |
|
|
|
|
|
append = TRUE |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
write_csv(path, append = fs::file_exists(path)) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ("SBoE ID" %in% names(data)) { |
|
|
if ("SBoE ID" %in% names(data)) { |