Created
December 30, 2021 20:10
-
-
Save dickoa/391f0efb8a5e6b80aae09440b18437ae to your computer and use it in GitHub Desktop.
Have all repeat into a list of data.frame
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' @noRd | |
repeat_to_df <- function(x, form) { | |
nm <- unique(form$name[form$type %in% "begin_repeat"]) | |
nm <- intersect(names(x), nm) | |
if (length(nm) > 0) { | |
x <- lapply(nm, function(n) { | |
res <- x[[n]] | |
res <- res[vapply(res, is.data.frame, logical(1))] | |
res <- rbindlist(res, fill = TRUE) | |
}) | |
} else { | |
x <- NULL | |
} | |
x | |
} | |
#' @noRd | |
kobo_repeat_df <- function(x, form) { | |
if (is.null(x)) | |
return(NULL) | |
x <- repeat_to_df(x, form) | |
lapply(x, function(x) | |
if (is.data.frame(x)) | |
list(x, repeat_to_df(x, form)) | |
else NULL) | |
} |
Author
dickoa
commented
Dec 30, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment