.SD <- NULL
library(jsonlite)
f <- list.files("inst/extdata/NSSH/", pattern = ".*6[0-9]{2}[AB]\\.json", recursive = TRUE, full.names = TRUE)
for (ff in f) {

  res <- data.table::rbindlist(lapply(lapply(read_json(ff), function(x) lapply(x, data.frame)), data.table::rbindlist), fill = TRUE)
  res$hgroup <- factor(res$header)

  .processHeader <- function(x) {
    cat(paste0("### ", x[["part"]][1], ".", x[["headerid"]][1], " - ", x[["header"]][1], sep = "\n"))
    cat("\n")
    if (nrow(x) >= 1) {
      cat("\n")
      cat(paste0(x$content, "\n"), sep = "\n")
      cat("\n")
    }
  }

  res[, .processHeader(.SD), by = "hgroup"]
}


brownag/SoilKnowledgeBase documentation built on April 5, 2025, 1:32 a.m.