From 813ad7c006f85232d27b7e17d09061f62d808dba Mon Sep 17 00:00:00 2001 From: AAoritz Date: Wed, 28 Feb 2024 08:59:43 +0100 Subject: [PATCH] add example for nuts_test_multiple_versions(), fix n rows dropped --- R/nuts_aggregate.R | 1 + R/nuts_convert_version.R | 1 + R/nuts_test_multiple_versions.R | 19 +++++++++++++++++-- tests/testthat/test-nuts_convert_version.R | 1 - 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/R/nuts_aggregate.R b/R/nuts_aggregate.R index ae314b2..8f982fc 100644 --- a/R/nuts_aggregate.R +++ b/R/nuts_aggregate.R @@ -133,6 +133,7 @@ nuts_aggregate <- function(data, # Test for multiple versions data <- nuts_test_multiple_versions(group_vars = group_vars, multiple_versions = multiple_versions, data_versions = data_versions, data = data) + n_rows_dropped <- data[["n_rows_dropped"]] message_multiple_versions <- data[["message_multiple_versions"]] data <- data[["data"]] diff --git a/R/nuts_convert_version.R b/R/nuts_convert_version.R index 2a311df..9c8ff89 100644 --- a/R/nuts_convert_version.R +++ b/R/nuts_convert_version.R @@ -142,6 +142,7 @@ nuts_convert_version <- # Test for multiple versions data <- nuts_test_multiple_versions(group_vars = group_vars, multiple_versions = multiple_versions, data_versions = data_versions, data = data) + n_rows_dropped <- data[["n_rows_dropped"]] message_multiple_versions <- data[["message_multiple_versions"]] data <- data[["data"]] diff --git a/R/nuts_test_multiple_versions.R b/R/nuts_test_multiple_versions.R index 6afc61e..c7cf6a5 100644 --- a/R/nuts_test_multiple_versions.R +++ b/R/nuts_test_multiple_versions.R @@ -10,6 +10,21 @@ #' #' @return A tibble containing NUTS codes and a message with the results of the test. #' +#' @examples +#' library(dplyr) +#' df <- manure %>% +#' filter(nchar(geo) == 5) %>% +#' select(geo, indic_ag, values) %>% +#' distinct(geo, .keep_all = T) %>% +#' nuts_classify(nuts_code = "geo", +#' group_vars = "indic_ag", +#' data = .) +#' +#' nuts_test_multiple_versions(group_vars = "indic_ag", +#' multiple_versions = "most_frequent", +#' data_versions = df$versions_data, +#' data = df$data) +#' #' @export nuts_test_multiple_versions = function(group_vars, multiple_versions, data_versions, data) { @@ -56,8 +71,8 @@ nuts_test_multiple_versions = function(group_vars, multiple_versions, data_versi c("v" = "{.blue Version is {.red unique}.}") } - data_list <- list(data, message_multiple_versions) - names(data_list) <- c("data", "message_multiple_versions") + data_list <- list(data, n_rows_dropped, message_multiple_versions) + names(data_list) <- c("data", "n_rows_dropped", "message_multiple_versions") return(data_list) } diff --git a/tests/testthat/test-nuts_convert_version.R b/tests/testthat/test-nuts_convert_version.R index 7014b82..82de359 100644 --- a/tests/testthat/test-nuts_convert_version.R +++ b/tests/testthat/test-nuts_convert_version.R @@ -248,4 +248,3 @@ test_that("Feeding multiple NUTS versions within groups. Option most frequent.", c(1005, 5) ) }) -