From 18b5c354a0235bf0d0654cff3403ebc0ce4157a1 Mon Sep 17 00:00:00 2001 From: atn38-crwr-d07322 Date: Tue, 26 Apr 2022 16:04:01 -0500 Subject: [PATCH] feat: new function get_dataset_level_element #2 #9 --- R/get_datasetlevel_element.R | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 R/get_datasetlevel_element.R diff --git a/R/get_datasetlevel_element.R b/R/get_datasetlevel_element.R new file mode 100644 index 0000000..e0cc470 --- /dev/null +++ b/R/get_datasetlevel_element.R @@ -0,0 +1,34 @@ +#' Title +#' +#' @param corpus +#' +#' @return +#' @export +#' +#' @examples +get_datasetlevel_element <- + function(corpus, element_names, parse_function) { + vw <- list() + for (i in seq_along(corpus)) { + pk <- parse_packageId(names(corpus)[[i]]) + scope <- pk[["scope"]] + id <- pk[["id"]] + rev <- pk[["rev"]] + + ddf <- data.frame() + if (recursive_check(corpus[[i]][["dataset"]], element_names = element_names)) { + d <- handle_one(corpus[[i]][["dataset"]][[element_names]]) + ddf <- + data.table::rbindlist(lapply(seq_along(d), function(x) + parse_function(d[[x]])), fill = TRUE) + n <- ncol(ddf) + cols <- c((n+1):(n+3), 1:n) + ddf$scope <- scope + ddf$id <- id + ddf$rev <- rev + ddf <- subset(ddf, select = cols) + } + vw[[i]] <- ddf + } + return(data.table::rbindlist(vw)) + }