From acdaf5cb8f4f34b1e24460655fd7a6a877f553b3 Mon Sep 17 00:00:00 2001 From: Thierry Onkelinx Date: Sat, 24 Aug 2024 16:18:39 +0200 Subject: [PATCH] read_vc() returns the variable descriptions as attributes --- R/read_vc.R | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/R/read_vc.R b/R/read_vc.R index 5cabdae..72a85b7 100644 --- a/R/read_vc.R +++ b/R/read_vc.R @@ -127,15 +127,30 @@ read_vc.character <- function(file, root = ".") { details = details, optimize = optimize ) - names(file) <- - c( + names(file) <- c( meta_data[["..generic"]][["data_hash"]], meta_data[["..generic"]][["hash"]] ) attr(raw_data, "source") <- file + + has_description <- vapply( + details, FUN.VALUE = logical(1), + FUN = function(x) { + "description" %in% names(x) + } + ) + has_description <- names(has_description)[has_description] + if (length(has_description) > 0) { + for (desc in has_description) { + attr(raw_data[[desc]], "description") <- details[[desc]]$description + } + } + return(raw_data) } + + reinstate <- function(raw_data, col_names, col_classes, details, optimize) { # reinstate factors for (id in col_names[col_classes == "factor"]) {