From 4a022b97fe0ba60106360d60ce0c1f6eed984d9a Mon Sep 17 00:00:00 2001 From: Mauro Loprete Date: Thu, 7 Nov 2024 22:04:16 -0300 Subject: [PATCH 1/7] Extract survey annual --- R/PanelSurvey.R | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/R/PanelSurvey.R b/R/PanelSurvey.R index f092511..48fa281 100644 --- a/R/PanelSurvey.R +++ b/R/PanelSurvey.R @@ -79,34 +79,34 @@ extract_surveys <- function(RotativePanelSurvey, index = NULL, monthly = NULL, a warning("At least one interval argument must be different from NULL. Returning the implantation survey.") annual <- 1 } - + if (!inherits(RotativePanelSurvey, "RotativePanelSurvey")) { stop("The `RotativeSurvey` argument must be an object of class `RotativePanelSurvey`") } - + follow_up <- RotativePanelSurvey$follow_up - + if (!is.null(index)) { return(PoolSurvey$new(list(follow_up = follow_up[index]))) } - + dates <- as.Date(sapply(unname(follow_up), function(x) x$edition)) - + ts_series <- stats::ts(1:length(follow_up), start = c(as.numeric(format(min(dates), "%Y")), as.numeric(format(min(dates), "%m"))), frequency = 12) - + apply_interval <- function(ts_series, start_year, start_month, end_year, end_month) { as.vector(stats::window(ts_series, start = c(start_year, start_month), end = c(end_year, end_month))) } - + apply_func <- if (use.parallel) { requireNamespace("parallel") parallel::mclapply } else { base::lapply } - + results <- list() - + # Crear solo los intervalos especificados y no dejar listas vacías month_names <- c("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December") if (!is.null(monthly)) { @@ -116,19 +116,15 @@ extract_surveys <- function(RotativePanelSurvey, index = NULL, monthly = NULL, a results$monthly[[month_names[month]]] <- follow_up[indices] } } - + if (!is.null(annual)) { results$annual <- list() - if (RotativePanelSurvey$implantation$periodicity != "Annual") { - for (year in annual) { - indices <- apply_interval(ts_series, year, 1, year, 12) - results$annual[[as.character(year)]] <- follow_up[indices] - } - } else { - results$annual[["implantation"]] <- list(RotativePanelSurvey$implantation) + for (year in annual) { + indices <- apply_interval(ts_series, year, 1, year, 12) + results$annual[[as.character(year)]] <- follow_up[indices] } } - + quarter_names <- c("Q1", "Q2", "Q3", "Q4") if (!is.null(quarterly)) { results$quarterly <- list() @@ -139,7 +135,7 @@ extract_surveys <- function(RotativePanelSurvey, index = NULL, monthly = NULL, a results$quarterly[[quarter_names[quarter]]] <- follow_up[indices] } } - + biannual_names <- c("H1", "H2") if (!is.null(biannual)) { results$biannual <- list() @@ -150,7 +146,7 @@ extract_surveys <- function(RotativePanelSurvey, index = NULL, monthly = NULL, a results$biannual[[biannual_names[semester]]] <- follow_up[indices] } } - + return(PoolSurvey$new(results)) } From 5e8b9dac56a850703cdd421d958f3a5a187c6261 Mon Sep 17 00:00:00 2001 From: Mauro Loprete Date: Thu, 7 Nov 2024 22:05:34 -0300 Subject: [PATCH 2/7] Enhance load_survey function to support dynamic file handling and improve error checking for follow-up surveys --- R/load_survey.R | 186 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 163 insertions(+), 23 deletions(-) diff --git a/R/load_survey.R b/R/load_survey.R index fa458db..664d210 100644 --- a/R/load_survey.R +++ b/R/load_survey.R @@ -12,9 +12,12 @@ #' @examples #' set_engine("data.table") #' svy_example <- load_survey( -#' "https://raw.githubusercontent.com/metasurveyr/metasurvey_data/main/eaii/2019-2021.csv", +#' load_survey_example( +#' svy_type = "eaii", +#' svy_edition = "2019-2021" +#' ), #' svy_type = "eaii", -#' svy_edition = "2019-2021", +#' svy_edition = "eaii_2019-2021", #' svy_weight = add_weight(annual = "w_trans"), #' dec = "," #' ) @@ -82,6 +85,7 @@ load_survey <- function( #' @param svy_weight_follow_up Weight of the follow-up survey #' @keywords preprocessing #' @return RotativePanelSurvey object +#' @export load_panel_survey <- function( path_implantation, @@ -92,33 +96,146 @@ load_panel_survey <- function( names_survey <- gsub( "\\..*", "", - list.files(path_follow_up, full.names = FALSE) + list.files(path_follow_up, full.names = FALSE, pattern = ".csv") ) + + if (length(names(svy_weight_follow_up)) > 1) { + stop( + "The follow-up survey must have a single weight time pattern" + ) + } + + time_pattern_follow_up <- names(svy_weight_follow_up) + + if (is(svy_weight_follow_up[[1]], "list")) { + svy_weight_follow_up <- svy_weight_follow_up[[1]] + } - path_survey <- list.files(path_follow_up, full.names = TRUE) + path_survey <- list.files(path_follow_up, full.names = TRUE, pattern = ".csv") + + names(path_survey) <- names_survey + implantation <- load_survey( path_implantation, svy_type = svy_type, - svy_edition = "2023", + svy_edition = basename(path_implantation) , svy_weight = svy_weight_implantation ) - - follow_up <- lapply( - X = names(path_survey), - FUN = function(x) { - load_survey( - path_survey[[x]], - svy_type = svy_type, - svy_edition = x, - svy_weight = svy_weight_follow_up - ) + + if (!is.null(svy_weight_follow_up$replicate_path)) { + path_file <- svy_weight_follow_up$replicate_path + path_file_final <- c() + + for (i in path_file) { + if(file.info(i)$isdir) { + path_file_final <- c(path_file_final, list.files(i, full.names = TRUE,pattern = ".rds")) + } else { + path_file_final <- c(path_file_final, i) + } } - ) - - names(follow_up) <- names_survey + + names_year_month <- sapply( + X = basename(path_file_final), + FUN = function(x) { + time_pattern <- extract_time_pattern(x) + if (time_pattern$periodicity != "Monthly") { + stop( + message( + "The periodicity of the file is not monthly" + ) + ) + } else { + return( + time_pattern$year * 100 + time_pattern$month + ) + } + }, + USE.NAMES = FALSE + ) + + names(path_file_final) <- names_year_month + + + svy_weight_follow_up <- lapply( + X = as.character(names_year_month), + FUN = function(x) { + + replicate = list( + add_replicate( + "W", + replicate_path = unname(path_file_final[x]), + replicate_id = c("ID" = "ID"), + replicate_pattern = "wr[0-9]+", + replicate_type = "bootstrap" + ) + ) + + names(replicate) <- time_pattern_follow_up + + return(replicate) + + } + ) + + names(svy_weight_follow_up) <- names_year_month + + names_path_survey_year_month <- sapply( + X = names(path_survey), + FUN = function(x) { + time_pattern <- extract_time_pattern(x) + if (time_pattern$periodicity != "Monthly") { + stop( + message( + "The periodicity of the file is not monthly" + ) + ) + } else { + return( + time_pattern$year * 100 + time_pattern$month + ) + } + }, + USE.NAMES = FALSE + ) + + names(path_survey) <- names_path_survey_year_month + + follow_up <- lapply( + X = 1:length(path_survey), + FUN = function(x) { + y = path_survey[[x]] + z = names(path_survey)[x] + svy_weight = unname(svy_weight_follow_up[z])[[1]] + + + load_survey( + y, + svy_type = svy_type, + svy_edition = basename(y), + svy_weight = svy_weight + ) + } + ) + + names(follow_up) <- names_survey + } else { + follow_up <- lapply( + X = names(path_survey), + FUN = function(x) { + load_survey( + path_survey[[x]], + svy_type = svy_type, + svy_edition = x, + svy_weight = svy_weight_follow_up + ) + } + ) + + names(follow_up) <- names_survey + } return( RotativePanelSurvey$new( @@ -143,19 +260,42 @@ load_panel_survey <- function( read_file <- function(file, .args = NULL) { .extension <- gsub(".*\\.", "", file) + .file_name <- basename(file) + .file_name <- gsub("\\..*", "", .file_name) + .path_without_extension <- gsub("\\..*", "", file) + .output_file <- paste0(.path_without_extension, ".csv") + + + + if (.extension != ".csv" && !file.exists(.output_file)) { + + requireNamespace("rio", quietly = TRUE) + + rio::convert( + in_file = file, + out_file = .output_file + ) + .extension <- "csv" + } else { + .extension <- "csv" + } + .read_function <- switch(.extension, sav = list(package = "foreign", read_function = "read.spss"), dta = list(package = "foreign", read_function = "read.dta"), csv = list(package = "data.table", read_function = "fread"), xlsx = list(package = "openxlsx", read_function = "read.xlsx"), + rds = list(package = "base", read_function = "readRDS"), stop("Unsupported file type: ", .extension) ) require(.read_function$package, character.only = TRUE) if (is.null(.args)) { - .args <- list(file) + .args <- list(.output_file) names(.args) <- names(formals(.read_function$read_function)[1]) + } else { + .args$file <- .output_file } .names_args <- names(.args) @@ -164,7 +304,8 @@ read_file <- function(file, .args = NULL) { .names_args <- .names_args[!.names_args %in% .metadata_args] - do.call(.read_function$read_function, args = .args[.names_args]) + df = do.call(.read_function$read_function, args = .args[.names_args]) + return(data.table::data.table(df)) } @@ -224,8 +365,6 @@ load_survey.data.table <- function(...) { } - - Survey <- Survey$new( data = svy, edition = .args$svy_edition, @@ -235,8 +374,9 @@ load_survey.data.table <- function(...) { weight = .args$svy_weight, recipes = .args$recipes %||% NULL ) + + - print(.args$bake) if (.args$bake %||% FALSE) { return(bake_recipes(Survey)) } else { From a195a7e27ba03536b2c0b70f5043bc09576cfad5 Mon Sep 17 00:00:00 2001 From: Mauro Loprete Date: Thu, 7 Nov 2024 22:06:03 -0300 Subject: [PATCH 3/7] Remove redundant check for new variables in step_compute_survey function --- R/steps.R | 4 ---- 1 file changed, 4 deletions(-) diff --git a/R/steps.R b/R/steps.R index d1f4149..f071fba 100644 --- a/R/steps.R +++ b/R/steps.R @@ -221,10 +221,6 @@ step_compute_survey <- function(svy, ..., .by = NULL, use_copy = use_copy_defaul not_in_data <- !(.new_vars %in% names_vars) .new_vars <- .new_vars[not_in_data] - if (length(.new_vars) == 0) { - stop("No new variable created") - } - step <- Step$new( name = paste("New variable:", paste(.new_vars, collapse = ", ")), edition = get_edition(svy), From 1350a61d73c9f4a75ca4c904d56ab6ac80c77847 Mon Sep 17 00:00:00 2001 From: Mauro Loprete Date: Thu, 7 Nov 2024 22:06:36 -0300 Subject: [PATCH 4/7] Optime svrep design --- R/survey.R | 39 ++++++++++++++++++++++++++++++++------- R/workflow.R | 1 + 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/R/survey.R b/R/survey.R index 78b7d0a..c133020 100644 --- a/R/survey.R +++ b/R/survey.R @@ -11,13 +11,14 @@ Survey <- R6Class( recipes = list(), workflows = list(), design = NULL, - initialize = function(data, edition, type, psu, engine, weight, design = NULL, steps = NULL, recipes = NULL) { + initialize = function(data, edition, type, psu, engine, weight, design = NULL, steps = NULL, recipes = list()) { self$data <- data time_pattern <- validate_time_pattern( svy_type = type, svy_edition = edition ) + weight_list <- validate_weight_time_pattern(data, weight) @@ -38,13 +39,30 @@ Survey <- R6Class( calibrate.formula = ~1 ) } else { - survey::svrepdesign( + + + aux_vars = c(x$weight, x$replicate_id) + data_aux = data[,aux_vars,with = FALSE] + data_aux = merge( + x$replicate_file[,1:11], + data_aux, + by.x = names(x$replicate_id), + by.y = x$replicate_id + ) + + design = survey::svrepdesign( id = psu, weights = as.formula(paste("~", x$weight)), - data = merge(data, x$replicate_file, by.x = names(x$replicate_id), by.y = x$replicate_id), + data = data_aux, repweights = x$replicate_pattern, type = x$replicate_type ) + + + data = merge(data, x$replicate_file, by.x = names(x$replicate_id), by.y = x$replicate_id) + design$variables <- data + design$repweights <- x$replicate_file + return(design) } } ) @@ -56,7 +74,7 @@ Survey <- R6Class( self$default_engine <- engine self$weight <- weight_list self$design <- design_list - self$recipes <- list(recipes) + self$recipes <- if (is.null(recipes)) list() else list(recipes) self$workflows <- list() self$periodicity <- time_pattern$svy_periodicity }, @@ -94,6 +112,13 @@ Survey <- R6Class( self$update_design() }, add_recipe = function(recipe, bake = lazy_default()) { + + if ((self$edition != recipe$edition)) { + stop("Invalid Recipe: \n", recipe$name, "\nEdition of survey: ", self$edition, "\nEdition of recipe: ", recipe$edition) + } + + + index_recipe <- length(self$recipes) + 1 self$recipes[[index_recipe]] <- recipe }, @@ -147,7 +172,6 @@ Survey <- R6Class( ) } else { survey::svrepdesign( - id = ~1, weights = as.formula(paste("~", x$weight)), data = merge(self$data, x$replicate_file, by.x = names(x$replicate_id), by.y = x$replicate_id), repweights = x$replicate_pattern, @@ -563,7 +587,8 @@ cat_design_type <- function(self, design_name) { #' cat_recipes <- function(self) { - if (is.null(self$recipes)) { + + if (is.null(self$recipes) || length(self$recipes) == 0) { return("None") } @@ -664,7 +689,7 @@ bake_recipes <- function(svy) { X = seq_along(recipes), FUN = function(x) { recipes[[x]]$clone() - } + } ) for (i in seq_along(recipes)) { diff --git a/R/workflow.R b/R/workflow.R index d4195c8..eddbeef 100644 --- a/R/workflow.R +++ b/R/workflow.R @@ -117,6 +117,7 @@ workflow_pool <- function(survey, ..., estimation_type = "monthly") { name_function <- deparse(call[[1]]) call[["design"]] <- substitute(design) call <- as.call(call) + # Evaluamos la función en el entorno estimation <- eval(call, envir = list(design = survey_item$design[[estimation_type]])) From 14cf5cc17603e573866c519d449f3812f27b6e6c Mon Sep 17 00:00:00 2001 From: Mauro Loprete Date: Thu, 7 Nov 2024 22:07:13 -0300 Subject: [PATCH 5/7] Fix extract_time_pattern --- R/utils.R | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/R/utils.R b/R/utils.R index 415229e..c77cc75 100644 --- a/R/utils.R +++ b/R/utils.R @@ -67,6 +67,8 @@ validate_replicate <- function(svy, replicate) { )) } } + + replicate_file <- read_file(replicate$replicate_path) @@ -304,8 +306,8 @@ set_lazy_processing <- function(lazy) { extract_time_pattern <- function(svy_edition) { # Limpiar la entrada: reemplazar espacios y guiones por guiones bajos y quitar guiones bajos extra - svy_edition <- gsub("[\\s\\-\\/]+", "_", svy_edition) - svy_edition <- gsub("[_*]+", "_", svy_edition) + svy_edition <- gsub("[\\s\\-\\/]+", "_", svy_edition, perl = TRUE) + svy_edition <- gsub("[_*]+", "_", svy_edition, perl = TRUE) svy_edition <- trimws(svy_edition, which = "both") # Inicializar variables @@ -317,13 +319,13 @@ extract_time_pattern <- function(svy_edition) { periodicity <- NA # Extraer el tipo si hay texto al inicio - if (grepl("^[A-Za-z]+", svy_edition)) { - type <- sub("_.*", "", svy_edition) - svy_edition <- sub("^[A-Za-z]+_*", "", svy_edition, perl = TRUE) + if (grepl("$[^0-9]*", svy_edition)) { + type <- sub("_.*", "", svy_edition,perl = TRUE) + svy_edition <- gsub("[^0-9]*", "", svy_edition, perl = TRUE) } # Caso: Mensual en formato YYYYMM (e.g., "202312") - if (grepl("^(\\d{4})(\\d{2})$", svy_edition)) { + if (grepl("^(\\d{4})(\\d{2})$", svy_edition) && as.numeric(sub("^(\\d{4})(\\d{2})$", "\\2", svy_edition)) <= 12) { year <- as.numeric(sub("^(\\d{4})(\\d{2})$", "\\1", svy_edition)) month <- as.numeric(sub("^(\\d{4})(\\d{2})$", "\\2", svy_edition)) @@ -335,7 +337,7 @@ extract_time_pattern <- function(svy_edition) { } # Caso: Mensual en formato MMYYYY (e.g., "122023") - } else if (grepl("^(\\d{2})(\\d{4})$", svy_edition)) { + } else if (grepl("^(\\d{2})(\\d{4})$", svy_edition) && as.numeric(sub("^(\\d{2})(\\d{4})$", "\\1", svy_edition)) <= 12) { month <- as.numeric(sub("^(\\d{2})(\\d{4})$", "\\1", svy_edition)) year <- as.numeric(sub("^(\\d{2})(\\d{4})$", "\\2", svy_edition)) @@ -347,7 +349,7 @@ extract_time_pattern <- function(svy_edition) { } # Caso: Mensual con formato MM_YYYY o MM-YYYY (e.g., "01_2023", "12_2023") - } else if (grepl("^(\\d{2})[_-](\\d{4})$", svy_edition)) { + } else if (grepl("^(\\d{2})[_-](\\d{4})$", svy_edition) && as.numeric(sub("^(\\d{2})[_-](\\d{4})$", "\\1", svy_edition)) <= 12) { month <- as.numeric(sub("^(\\d{2})[_-](\\d{4})$", "\\1", svy_edition)) year <- as.numeric(sub("^(\\d{2})[_-](\\d{4})$", "\\2", svy_edition)) @@ -359,7 +361,7 @@ extract_time_pattern <- function(svy_edition) { } # Caso: Mensual con formato YYYY_MM o YYYY-MM (e.g., "2023_12") - } else if (grepl("^(\\d{4})[_-](\\d{2})$", svy_edition)) { + } else if (grepl("^(\\d{4})[_-](\\d{2})$", svy_edition) && as.numeric(sub("^(\\d{4})[_-](\\d{2})$", "\\2", svy_edition)) <= 12) { year <- as.numeric(sub("^(\\d{4})[_-](\\d{2})$", "\\1", svy_edition)) month <- as.numeric(sub("^(\\d{4})[_-](\\d{2})$", "\\2", svy_edition)) @@ -371,19 +373,19 @@ extract_time_pattern <- function(svy_edition) { } # Caso: Encuesta con rango de años (e.g., "2019_2021") - } else if (grepl("^(\\d{4})[_-](\\d{4})$", svy_edition)) { + } else if (grepl("^(\\d{4})(\\d{4})$", svy_edition)) { years <- as.numeric(unlist(regmatches(svy_edition, gregexpr("\\d{4}", svy_edition)))) year_start <- min(years) year_end <- max(years) periodicity <- if (year_end - year_start + 1 == 3) "Trianual" else "Multianual" # Caso: Anual (e.g., "2023") - } else if (grepl("^\\d{4}$", svy_edition)) { + } else if (grepl("^\\d{4}$", svy_edition) && as.numeric(svy_edition) >= 1900) { year <- as.numeric(svy_edition) periodicity <- "Annual" # Caso: Mensual con formato YY_MM o MM_YY (e.g., "23_05" que se interpreta como "2023-05") - } else if (grepl("^(\\d{2})[_-](\\d{2})$", svy_edition)) { + } else if ((grepl("^(\\d{2})[_-](\\d{2})$", svy_edition) || grepl("^(\\d{2})(\\d{2})$", svy_edition))) { part1 <- as.numeric(sub("^(\\d{2})[_-](\\d{2})$", "\\1", svy_edition)) part2 <- as.numeric(sub("^(\\d{2})[_-](\\d{2})$", "\\2", svy_edition)) @@ -395,7 +397,15 @@ extract_time_pattern <- function(svy_edition) { year <- 2000 + part1 # Interpretar como 20XX month <- part2 } else { - periodicity <- "Formato incorrecto" + part1 <- as.numeric(sub("^(\\d{2})(\\d{2})$", "\\1", svy_edition)) + part2 <- as.numeric(sub("^(\\d{2})(\\d{2})$", "\\2", svy_edition)) + if (part1 >= 1 && part1 <= 12) { + month <- part1 + year <- 2000 + part2 # Interpretar como 20XX + } else if (part2 >= 1 && part2 <= 12) { + year <- 2000 + part1 # Interpretar como 20XX + month <- part2 + } } if (!is.na(month) && month >= 1 && month <= 12) { From c66df84922dd443c369f64f3a2a6c1da2065b166 Mon Sep 17 00:00:00 2001 From: Mauro Loprete Date: Thu, 7 Nov 2024 22:07:51 -0300 Subject: [PATCH 6/7] Update package version, add load_panel_survey export, and enhance load_survey examples --- .Rbuildignore | 2 +- DESCRIPTION | 5 +- NAMESPACE | 1 + man/load_survey.Rd | 7 +- vignettes/eai.Rmd | 301 --------------------------------------------- vignettes/ech.Rmd | 29 +++++ 6 files changed, 39 insertions(+), 306 deletions(-) delete mode 100644 vignettes/eai.Rmd create mode 100644 vignettes/ech.Rmd diff --git a/.Rbuildignore b/.Rbuildignore index b17eccc..28c33dc 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -33,4 +33,4 @@ recetas_ech.R test.R test_api.R test_recipes.R -test_recipes.R +test_recipes.R \ No newline at end of file diff --git a/DESCRIPTION b/DESCRIPTION index 7b3b573..2938a05 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: metasurvey Title: Survey Processing with Meta-Programming -Version: 0.0.1.9008 +Version: 0.0.1.9010 URL: https://github.com/metasurveyr/metasurvey Authors@R: c( @@ -44,7 +44,8 @@ Suggests: knitr (>= 1.33), foreign (>= 0.8-81), rmarkdown (>= 2.11), - parallel (>= 4.1.1) + parallel (>= 4.1.1), + rio (>= 0.5.27) Config/testthat/edition: 3 Encoding: UTF-8 LazyData: true diff --git a/NAMESPACE b/NAMESPACE index faa10cd..a4c1a7c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -18,6 +18,7 @@ export(get_recipe) export(get_steps) export(group_dates) export(lazy_default) +export(load_panel_survey) export(load_survey) export(load_survey_example) export(read_recipe) diff --git a/man/load_survey.Rd b/man/load_survey.Rd index fff8f64..a17894b 100644 --- a/man/load_survey.Rd +++ b/man/load_survey.Rd @@ -38,9 +38,12 @@ Load survey \examples{ set_engine("data.table") svy_example <- load_survey( - "https://raw.githubusercontent.com/metasurveyr/metasurvey_data/main/eaii/2019-2021.csv", + load_survey_example( + svy_type = "eaii", + svy_edition = "2019-2021" + ), svy_type = "eaii", - svy_edition = "2019-2021", + svy_edition = "eaii_2019-2021", svy_weight = add_weight(annual = "w_trans"), dec = "," ) diff --git a/vignettes/eai.Rmd b/vignettes/eai.Rmd deleted file mode 100644 index 2e1675a..0000000 --- a/vignettes/eai.Rmd +++ /dev/null @@ -1,301 +0,0 @@ ---- -title: "eai" -output: rmarkdown::html_vignette -vignette: > - %\VignetteIndexEntry{eai} - %\VignetteEngine{knitr::rmarkdown} - %\VignetteEncoding{UTF-8} ---- - -```{r, include = FALSE} -knitr::opts_chunk$set( - collapse = TRUE, - comment = "#>" -) -``` - - -Esta encuesta es utilizada para obtener información sobre las actividades de innovación e investigación y desarrollo en las empresas, instituciones y organismos del país, es realizada por la Agencia Nacional de Innovación e Investigación (ANII) en conjunto con el Instituto Nacional de Estadística (INE). -Los microdatos oficiales se encuentran diposibles en [PRISMA](https://prisma.uy/indicadores/innovacion/periodo-actual) junto con la documentación de la encuesta. En el paquete se encuentra el mismo archivo de microdatos en formato CSV unicamente -con fines de ejemplo. - - -## Configuración del motor - -El paquete tiene diferentes motores para trabajar con datos, en este caso se usará el motor `data.table`. Para cambiar el motor se puede usar la función `set_engine` y para ver los motores disponibles se puede usar la función `show_engines`, -en este ejemplo se usará el motor `data.table`. - -```{r setup} -library(metasurvey) -``` - -## Carga de datos - -Al cargar la encuesta se utiliza la función `load_survey`, actualmente se pueden cargar encuestas en los siguientes formatos: - -- CSV (con el motor `data.table`) -- XLSX (con el motor `tidyverse`) -- SPSS (con el motor `data.table` o `tidyverse`) - -Además de los microdatos, es necesario cargar algunos metadatos para poder trabajar con la encuesta, actualmente es requerida la siguiente información: - -- Tipo de encuesta, por ejemplo: EPH, ECH, EAII, etc. -- Edición de la encuesta, es necesario para poder buscar recetas predefinidas y compartir recetas entre diferentes usuarios. -- Variable de ponderación, es necesario para poder realizar estimaciones y definir el diseño muestral de la encuesta. - -Una vez cargada la encuesta obtendremos un objeto de la clase `Survey` que contiene los microdatos y los metadatos de la encuesta. - -```{r} -# Tipo de encuesta: ECH -# Edición de la encuesta: 2018 -# Variable de ponderación: pesoano - -svy_example <- metasurvey::load_survey( - "https://raw.githubusercontent.com/metasurveyr/metasurvey_data/main/eaii/2019-2021.csv", - svy_type = "eaii", - svy_edition = "2019-2021", - svy_weight = add_weight( - annual = "w_trans" - ), - dec = ",", - svy_psu = "ID_Estadistico" -) - -class(svy_example) -``` - -De esta forma se carga la encuesta en memoria al ser un objeto de la clase `Survey` se pueden realizar diferentes operaciones con ella, como recodificar variables, crear nuevas variables, aunque siempre se pueden -obtener los datos en formato `data.table` o `tibble` para trabajar con ellos de forma más directa. - -```{r} -survey_to_data_frame(svy_example)[1:5, 1:3] -survey_to_tibble(svy_example)[1:5, 1:3] -get_data(svy_example)[1:5, 1:3] -``` - -# Uso de recipes y workflows - -```{r} -set_lazy_processing(FALSE) -eaii_2019 <- metasurvey::load_survey( - "https://raw.githubusercontent.com/metasurveyr/metasurvey_data/main/eaii/2019-2021.csv", - svy_type = "eaii", - svy_edition = "2019-2021", - svy_weight = add_weight( - annual = "w_trans" - ), - dec = "," -) -``` - -## Recodificación de variables con steps y recipes - -En este ejemplo se mostrará como crear variables relacionadas al sector, edad de la empresa, tamaño de la empresa y si la empresa es innovadora o no además del tipo de actividad de innovación que realiza de forma tal -de poder recrear este gráfico de la sección de [Innovación](https://prisma.uy/indicadores/innovacion/periodo-actual/?grafico=grafico-5.1§or=Todos los sectores&subsector=Todos los subsectores) de PRISMA. - -En este portal se pueden obtener datos a nivel de todas las empresas aunque también se pueden obtener estimaciones en diferentes dominios de interés, como el tamaño de la empresa, sector, edad de la empresa, dichos dominios -no se encuentran disponibles de forma directa en los microdatos oficiales, por lo que es necesario realizar una recodificación de las variables para poder obtener las estimaciones deseadas. - -### Tamaño de la empresa - -En base al decreto Nº 504/007 se clasifican las empresas en tres categorías según la cantidad de trabajadores y el monto de las ventas, en este caso se recodificará la variable `IG_4_1_3` que representa la cantidad de trabajadores y la variable `IG_5_1_1_3` que representa el monto de las ventas. -El decreto Nº 504/007 establece las siguientes categorías: - -- **Pequeñas empresas**: Son las que ocupan no más de diecinueve (19) personas y cuyas ventas anuales excluído el IVA, no superan el equivalente a diez millones (10.000.000) de unidades indexadas (U.I.). - -- **Medianas empresas**: Son las que ocupan no más de noventa y nueve (99) personas y cuyas ventas anuales excluído el IVA, no superan el equivalente a setenta y cinco millones (75.000.000) de unidades indexadas (U.I.). - -- **Grandes empresas**: Son las que ocupan más de noventa y nueve (99) personas y cuyas ventas anuales excluído el IVA, superan el equivalente a setenta y cinco millones (75.000.000) de unidades indexadas (U.I.). - -```{r} -eaii_2019 <- eaii_2019 |> - metasurvey::step_recode( # Clasificación tamaño de la empresa decreto Nº 504/007 - new_var = cant_traba_tramo, - data.table::between(IG_4_1_3, 0, 4) ~ "1", - data.table::between(IG_4_1_3, 5, 19) ~ "2", - data.table::between(IG_4_1_3, 20, 99) ~ "3", - IG_4_1_3 > 99 ~ "4" - ) |> - metasurvey::step_recode( # Clasificación tamaño de la empresa decreto Nº 504/007 - new_var = ingreso_vta_pesos, - data.table::between(IG_5_1_1_3, 0, 9942787) ~ "1", - data.table::between(IG_5_1_1_3, 9942788, 49713934) ~ "2", # nolint - data.table::between(IG_5_1_1_3, 49713935, 372854507) ~ "3", # nolint - IG_5_1_1_3 > 372854507 ~ "4" - ) |> - metasurvey::step_recode( # Clasificación tamaño de la empresa decreto Nº 504/007 - new_var = tamanio, - cant_traba_tramo == "1" & ingreso_vta_pesos == "1" ~ "Pequenias", - cant_traba_tramo == "2" & ingreso_vta_pesos == "2" ~ "Pequenias", - cant_traba_tramo == "2" & ingreso_vta_pesos == "1" ~ "Pequenias", - cant_traba_tramo == "1" & ingreso_vta_pesos == "2" ~ "Pequenias", - cant_traba_tramo == "3" & ingreso_vta_pesos == "3" ~ "Medianas", - cant_traba_tramo == "3" & ingreso_vta_pesos == "2" ~ "Medianas", - cant_traba_tramo == "3" & ingreso_vta_pesos == "1" ~ "Medianas", - cant_traba_tramo == "1" & ingreso_vta_pesos == "3" ~ "Medianas", - cant_traba_tramo == "2" & ingreso_vta_pesos == "3" ~ "Medianas", - cant_traba_tramo == "4" & ingreso_vta_pesos == "4" ~ "Grandes", - cant_traba_tramo == "4" & ingreso_vta_pesos == "3" ~ "Grandes", - cant_traba_tramo == "4" & ingreso_vta_pesos == "2" ~ "Grandes", - cant_traba_tramo == "4" & ingreso_vta_pesos == "1" ~ "Grandes", - cant_traba_tramo == "1" & ingreso_vta_pesos == "4" ~ "Grandes", - cant_traba_tramo == "2" & ingreso_vta_pesos == "4" ~ "Grandes", - cant_traba_tramo == "3" & ingreso_vta_pesos == "4" ~ "Grandes" - ) -``` - -### Edad de la empresa - -Las empresas se clasifican en tres categorías según su edad, para ello se recodificará la variable `IG_3_5_1` que representa la fecha de fundación de la empresa. - -- **Jovenes**: Empresas con menos de 10 años de antigüedad. -- **Medianas**: Empresas con entre 11 y 20 años de antigüedad. -- **Maduras**: Empresas con más de 20 años de antigüedad. - -```{r} -eaii_2019 <- eaii_2019 |> - metasurvey::step_compute( - edad = difftime( - "2019-01-01", - as.Date(paste(IG_3_5_1, "01", "01", sep = "-")), - units = "weeks" - ) / 52 - ) |> - metasurvey::step_recode( - edad_tramos, - data.table::between(edad, 0, 10) ~ "Jovenes", - data.table::between(edad, 11, 20) ~ "Medianas", - edad > 20 ~ "Maduras" - ) -``` - -### Tipo de empresa - -Las empresas se clasifican en tres categorías según su tipo, para ello se recodificará la variable `IG_3_6` que representa en el cuestionario a la siguiente pregunta "Indique si la empresa era pública, privada o mixta en el año 2021". - - -```{r} -eaii_2019 <- eaii_2019 |> - metasurvey::step_recode( - tipo_empresa, - IG_3_6 == 1 ~ "Publica", - IG_3_6 == 2 ~ "Privada", - IG_3_6 == 3 ~ "Mixta" - ) -``` - - -### Sector CIUU - -Cada empresa se clasifica en un sector según la Clasificación Industrial Internacional Uniforme de todas las actividades económicas (CIUU), en este caso se recodificará la variable `Division` que representa el sector de la empresa. - -```{r} -eaii_2019 <- eaii_2019 |> - metasurvey::step_recode( - sector, - data.table::between(Division, 10, 33) ~ "Industria", - data.table::between(Division, 34, 99) ~ "Servicios", - Division == "E1" ~ "Servicios", - Division == "C1" ~ "Industria", - Division == "C2" ~ "Industria" - ) |> - metasurvey::step_compute( - subsector = Division - ) -``` - - - -### Realiza actividades de innovación - -En base a la pregunta "¿La empresa realizó actividades de innovación en el período 2019-2021?" se recodificará la variable `IG_6_1` que representa si la empresa realizó actividades de innovación en el período 2019-2021. - -```{r} -eaii_2019 <- eaii_2019 |> - metasurvey::step_recode( - new_var = realiza_innovacion, - B1_1_1 == 1 ~ 1, - B1_2_1 == 1 ~ 1, - B1_3_1 == 1 ~ 1, - B1_4_1 == 1 ~ 1, - B1_5_1 == 1 ~ 1, - B1_6_1 == 1 ~ 1, - B1_7_1 == 1 ~ 1, - B1_8_1 == 1 ~ 1, - B1_9_1 == 1 ~ 1, - .default = 0 - ) -``` - -De esta forma si se realiza una estimación de la cantidad de empresas que realizan actividades de innovación en el período 2019-2021 se puede obtener la siguiente tabla: - -```{r,eval = FALSE} -workflow( - list(eaii_2019), - survey::svymean( - ~realiza_innovacion - ), - estimation_type = "annual" -) -``` - -### Tipo de actividad de innovación - -```{r} -eaii_2019 <- eaii_2019 |> - step_compute( - software = ifelse( - B1_4_1 == 1, - 1, - 0 - ), - id_interna = ifelse( - B1_1_1 == 1, - 1, - 0 - ), - id_externa = ifelse( - B1_2_1 == 1, - 1, - 0 - ), - bienes_capital = ifelse( - B1_3_1 == 1, - 1, - 0 - ), - propiedad_intelectual = ifelse( - B1_5_1 == 1, - 1, - 0 - ), - ingenieria = ifelse( - B1_6_1 == 1, - 1, - 0 - ), - capacitacion = ifelse( - B1_7_1 == 1, - 1, - 0 - ), - marketing = ifelse( - B1_8_1 == 1, - 1, - 0 - ), - gestion = ifelse( - B1_9_1 == 1, - 1, - 0 - ) - ) -``` - -## Workflow - -Una vez realizada la recodificación de variables se puede obtener cada paso realizado con la función `get_steps` o visualizarlo en forma de DAG con la función - -```{r} -metasurvey::view_graph(eaii_2019) -``` diff --git a/vignettes/ech.Rmd b/vignettes/ech.Rmd new file mode 100644 index 0000000..f1faf96 --- /dev/null +++ b/vignettes/ech.Rmd @@ -0,0 +1,29 @@ +--- +title: "Use recipes" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Use recipes} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + + + +# Obtener recetas + +```{r} +library(metasurvey) +recetas_mercado_trabajo <- get_recipe( + "ech", + "2022", + topic = "ingreso" +) + +``` \ No newline at end of file From f710c6cebb6813b2849ada6f8ee2d65c64b08a93 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 8 Nov 2024 01:09:49 +0000 Subject: [PATCH 7/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .Rbuildignore | 2 +- R/PanelSurvey.R | 26 +++++++-------- R/load_survey.R | 85 +++++++++++++++++++++++------------------------ R/survey.R | 32 ++++++++---------- R/utils.R | 8 ++--- R/workflow.R | 2 +- vignettes/ech.Rmd | 9 +++-- 7 files changed, 78 insertions(+), 86 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index 28c33dc..b17eccc 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -33,4 +33,4 @@ recetas_ech.R test.R test_api.R test_recipes.R -test_recipes.R \ No newline at end of file +test_recipes.R diff --git a/R/PanelSurvey.R b/R/PanelSurvey.R index 48fa281..57a1794 100644 --- a/R/PanelSurvey.R +++ b/R/PanelSurvey.R @@ -79,34 +79,34 @@ extract_surveys <- function(RotativePanelSurvey, index = NULL, monthly = NULL, a warning("At least one interval argument must be different from NULL. Returning the implantation survey.") annual <- 1 } - + if (!inherits(RotativePanelSurvey, "RotativePanelSurvey")) { stop("The `RotativeSurvey` argument must be an object of class `RotativePanelSurvey`") } - + follow_up <- RotativePanelSurvey$follow_up - + if (!is.null(index)) { return(PoolSurvey$new(list(follow_up = follow_up[index]))) } - + dates <- as.Date(sapply(unname(follow_up), function(x) x$edition)) - + ts_series <- stats::ts(1:length(follow_up), start = c(as.numeric(format(min(dates), "%Y")), as.numeric(format(min(dates), "%m"))), frequency = 12) - + apply_interval <- function(ts_series, start_year, start_month, end_year, end_month) { as.vector(stats::window(ts_series, start = c(start_year, start_month), end = c(end_year, end_month))) } - + apply_func <- if (use.parallel) { requireNamespace("parallel") parallel::mclapply } else { base::lapply } - + results <- list() - + # Crear solo los intervalos especificados y no dejar listas vacías month_names <- c("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December") if (!is.null(monthly)) { @@ -116,7 +116,7 @@ extract_surveys <- function(RotativePanelSurvey, index = NULL, monthly = NULL, a results$monthly[[month_names[month]]] <- follow_up[indices] } } - + if (!is.null(annual)) { results$annual <- list() for (year in annual) { @@ -124,7 +124,7 @@ extract_surveys <- function(RotativePanelSurvey, index = NULL, monthly = NULL, a results$annual[[as.character(year)]] <- follow_up[indices] } } - + quarter_names <- c("Q1", "Q2", "Q3", "Q4") if (!is.null(quarterly)) { results$quarterly <- list() @@ -135,7 +135,7 @@ extract_surveys <- function(RotativePanelSurvey, index = NULL, monthly = NULL, a results$quarterly[[quarter_names[quarter]]] <- follow_up[indices] } } - + biannual_names <- c("H1", "H2") if (!is.null(biannual)) { results$biannual <- list() @@ -146,7 +146,7 @@ extract_surveys <- function(RotativePanelSurvey, index = NULL, monthly = NULL, a results$biannual[[biannual_names[semester]]] <- follow_up[indices] } } - + return(PoolSurvey$new(results)) } diff --git a/R/load_survey.R b/R/load_survey.R index 664d210..5278911 100644 --- a/R/load_survey.R +++ b/R/load_survey.R @@ -13,8 +13,8 @@ #' set_engine("data.table") #' svy_example <- load_survey( #' load_survey_example( -#' svy_type = "eaii", -#' svy_edition = "2019-2021" +#' svy_type = "eaii", +#' svy_edition = "2019-2021" #' ), #' svy_type = "eaii", #' svy_edition = "eaii_2019-2021", @@ -85,7 +85,7 @@ load_survey <- function( #' @param svy_weight_follow_up Weight of the follow-up survey #' @keywords preprocessing #' @return RotativePanelSurvey object -#' @export +#' @export load_panel_survey <- function( path_implantation, @@ -98,45 +98,45 @@ load_panel_survey <- function( "", list.files(path_follow_up, full.names = FALSE, pattern = ".csv") ) - + if (length(names(svy_weight_follow_up)) > 1) { stop( "The follow-up survey must have a single weight time pattern" ) } - + time_pattern_follow_up <- names(svy_weight_follow_up) - + if (is(svy_weight_follow_up[[1]], "list")) { - svy_weight_follow_up <- svy_weight_follow_up[[1]] + svy_weight_follow_up <- svy_weight_follow_up[[1]] } path_survey <- list.files(path_follow_up, full.names = TRUE, pattern = ".csv") - - + + names(path_survey) <- names_survey - + implantation <- load_survey( path_implantation, svy_type = svy_type, - svy_edition = basename(path_implantation) , + svy_edition = basename(path_implantation), svy_weight = svy_weight_implantation ) - + if (!is.null(svy_weight_follow_up$replicate_path)) { path_file <- svy_weight_follow_up$replicate_path path_file_final <- c() - + for (i in path_file) { - if(file.info(i)$isdir) { - path_file_final <- c(path_file_final, list.files(i, full.names = TRUE,pattern = ".rds")) + if (file.info(i)$isdir) { + path_file_final <- c(path_file_final, list.files(i, full.names = TRUE, pattern = ".rds")) } else { path_file_final <- c(path_file_final, i) } } - + names_year_month <- sapply( X = basename(path_file_final), FUN = function(x) { @@ -155,15 +155,14 @@ load_panel_survey <- function( }, USE.NAMES = FALSE ) - + names(path_file_final) <- names_year_month - - + + svy_weight_follow_up <- lapply( X = as.character(names_year_month), FUN = function(x) { - - replicate = list( + replicate <- list( add_replicate( "W", replicate_path = unname(path_file_final[x]), @@ -172,16 +171,15 @@ load_panel_survey <- function( replicate_type = "bootstrap" ) ) - + names(replicate) <- time_pattern_follow_up - + return(replicate) - } ) - + names(svy_weight_follow_up) <- names_year_month - + names_path_survey_year_month <- sapply( X = names(path_survey), FUN = function(x) { @@ -200,17 +198,17 @@ load_panel_survey <- function( }, USE.NAMES = FALSE ) - + names(path_survey) <- names_path_survey_year_month - + follow_up <- lapply( X = 1:length(path_survey), FUN = function(x) { - y = path_survey[[x]] - z = names(path_survey)[x] - svy_weight = unname(svy_weight_follow_up[z])[[1]] - - + y <- path_survey[[x]] + z <- names(path_survey)[x] + svy_weight <- unname(svy_weight_follow_up[z])[[1]] + + load_survey( y, svy_type = svy_type, @@ -219,7 +217,7 @@ load_panel_survey <- function( ) } ) - + names(follow_up) <- names_survey } else { follow_up <- lapply( @@ -233,7 +231,7 @@ load_panel_survey <- function( ) } ) - + names(follow_up) <- names_survey } @@ -264,13 +262,12 @@ read_file <- function(file, .args = NULL) { .file_name <- gsub("\\..*", "", .file_name) .path_without_extension <- gsub("\\..*", "", file) .output_file <- paste0(.path_without_extension, ".csv") - - - + + + if (.extension != ".csv" && !file.exists(.output_file)) { - requireNamespace("rio", quietly = TRUE) - + rio::convert( in_file = file, out_file = .output_file @@ -279,7 +276,7 @@ read_file <- function(file, .args = NULL) { } else { .extension <- "csv" } - + .read_function <- switch(.extension, sav = list(package = "foreign", read_function = "read.spss"), dta = list(package = "foreign", read_function = "read.dta"), @@ -304,7 +301,7 @@ read_file <- function(file, .args = NULL) { .names_args <- .names_args[!.names_args %in% .metadata_args] - df = do.call(.read_function$read_function, args = .args[.names_args]) + df <- do.call(.read_function$read_function, args = .args[.names_args]) return(data.table::data.table(df)) } @@ -374,8 +371,8 @@ load_survey.data.table <- function(...) { weight = .args$svy_weight, recipes = .args$recipes %||% NULL ) - - + + if (.args$bake %||% FALSE) { return(bake_recipes(Survey)) diff --git a/R/survey.R b/R/survey.R index c133020..ca4cb4e 100644 --- a/R/survey.R +++ b/R/survey.R @@ -18,7 +18,7 @@ Survey <- R6Class( svy_type = type, svy_edition = edition ) - + weight_list <- validate_weight_time_pattern(data, weight) @@ -39,27 +39,25 @@ Survey <- R6Class( calibrate.formula = ~1 ) } else { - - - aux_vars = c(x$weight, x$replicate_id) - data_aux = data[,aux_vars,with = FALSE] - data_aux = merge( - x$replicate_file[,1:11], + aux_vars <- c(x$weight, x$replicate_id) + data_aux <- data[, aux_vars, with = FALSE] + data_aux <- merge( + x$replicate_file[, 1:11], data_aux, by.x = names(x$replicate_id), by.y = x$replicate_id ) - - design = survey::svrepdesign( + + design <- survey::svrepdesign( id = psu, weights = as.formula(paste("~", x$weight)), data = data_aux, repweights = x$replicate_pattern, type = x$replicate_type ) - - - data = merge(data, x$replicate_file, by.x = names(x$replicate_id), by.y = x$replicate_id) + + + data <- merge(data, x$replicate_file, by.x = names(x$replicate_id), by.y = x$replicate_id) design$variables <- data design$repweights <- x$replicate_file return(design) @@ -112,13 +110,12 @@ Survey <- R6Class( self$update_design() }, add_recipe = function(recipe, bake = lazy_default()) { - if ((self$edition != recipe$edition)) { stop("Invalid Recipe: \n", recipe$name, "\nEdition of survey: ", self$edition, "\nEdition of recipe: ", recipe$edition) } - - - + + + index_recipe <- length(self$recipes) + 1 self$recipes[[index_recipe]] <- recipe }, @@ -587,7 +584,6 @@ cat_design_type <- function(self, design_name) { #' cat_recipes <- function(self) { - if (is.null(self$recipes) || length(self$recipes) == 0) { return("None") } @@ -689,7 +685,7 @@ bake_recipes <- function(svy) { X = seq_along(recipes), FUN = function(x) { recipes[[x]]$clone() - } + } ) for (i in seq_along(recipes)) { diff --git a/R/utils.R b/R/utils.R index c77cc75..d285b83 100644 --- a/R/utils.R +++ b/R/utils.R @@ -67,8 +67,8 @@ validate_replicate <- function(svy, replicate) { )) } } - - + + replicate_file <- read_file(replicate$replicate_path) @@ -320,7 +320,7 @@ extract_time_pattern <- function(svy_edition) { # Extraer el tipo si hay texto al inicio if (grepl("$[^0-9]*", svy_edition)) { - type <- sub("_.*", "", svy_edition,perl = TRUE) + type <- sub("_.*", "", svy_edition, perl = TRUE) svy_edition <- gsub("[^0-9]*", "", svy_edition, perl = TRUE) } @@ -385,7 +385,7 @@ extract_time_pattern <- function(svy_edition) { periodicity <- "Annual" # Caso: Mensual con formato YY_MM o MM_YY (e.g., "23_05" que se interpreta como "2023-05") - } else if ((grepl("^(\\d{2})[_-](\\d{2})$", svy_edition) || grepl("^(\\d{2})(\\d{2})$", svy_edition))) { + } else if ((grepl("^(\\d{2})[_-](\\d{2})$", svy_edition) || grepl("^(\\d{2})(\\d{2})$", svy_edition))) { part1 <- as.numeric(sub("^(\\d{2})[_-](\\d{2})$", "\\1", svy_edition)) part2 <- as.numeric(sub("^(\\d{2})[_-](\\d{2})$", "\\2", svy_edition)) diff --git a/R/workflow.R b/R/workflow.R index eddbeef..5e42d63 100644 --- a/R/workflow.R +++ b/R/workflow.R @@ -117,7 +117,7 @@ workflow_pool <- function(survey, ..., estimation_type = "monthly") { name_function <- deparse(call[[1]]) call[["design"]] <- substitute(design) call <- as.call(call) - + # Evaluamos la función en el entorno estimation <- eval(call, envir = list(design = survey_item$design[[estimation_type]])) diff --git a/vignettes/ech.Rmd b/vignettes/ech.Rmd index f1faf96..574ad1b 100644 --- a/vignettes/ech.Rmd +++ b/vignettes/ech.Rmd @@ -21,9 +21,8 @@ knitr::opts_chunk$set( ```{r} library(metasurvey) recetas_mercado_trabajo <- get_recipe( - "ech", - "2022", - topic = "ingreso" + "ech", + "2022", + topic = "ingreso" ) - -``` \ No newline at end of file +```