diff --git a/R/estimationdata.R b/R/estimationdata.R index 7425e9f..30eec75 100644 --- a/R/estimationdata.R +++ b/R/estimationdata.R @@ -129,9 +129,11 @@ EstimationData <- function(formula = NULL, "Use partial data (pairwise correlations)" = RemoveCasesWithAllNA(data.subset), stop(paste("Unknown 'missing' method:", missing))) data.for.estimation <- CopyAttributes(data.for.estimation, data.subset) - levels.pre <- unlist(lapply(data.for.estimation, levels)) + levels.pre <- paste0(rep(labels, vapply(data.for.estimation, nlevels, 0L)), ": ", + unlist(lapply(data.for.estimation, levels))) data.for.estimation <- RemoveMissingLevelsFromFactors(data.for.estimation) - levels.post <- unlist(lapply(data.for.estimation, levels)) + levels.post <- paste0(rep(labels, vapply(data.for.estimation, nlevels, 0L)), ": ", + unlist(lapply(data.for.estimation, levels))) levels.diff <- setdiff(levels.pre, levels.post) if (length(levels.diff) > 0) { diff --git a/tests/testthat/test-estimationdata.R b/tests/testthat/test-estimationdata.R index 85d0cff..aa365a9 100644 --- a/tests/testthat/test-estimationdata.R +++ b/tests/testthat/test-estimationdata.R @@ -51,15 +51,18 @@ attr(bank$Fees, "label") <- "Fees paid" attr(bank$Online, "label") <- "Online banking" -dat2 <- structure(list(Country = structure(c(1L, 4L, 2L, 3L), class = "factor", +test_that("DS-2626", +{ + dat2 <- structure(list(Country = structure(c(1L, 4L, 2L, 3L), class = "factor", .Label = c("Australia","Denmark", "Fiji", "France"), questiontype = "PickOne", name = "Country", label = "Country", question = "Country"), A = structure(c(1L, 2L, 3L, NA), class = "factor", .Label = c("1", "2", "3"), questiontype = "PickOne", name = "A", label = "A", question = "A")), class = "data.frame", row.names = c(NA, -4L)) -filt <- c(FALSE, TRUE, TRUE, TRUE) -EstimationData(~Country + A, data = dat2, subset = filt) - + filt <- c(FALSE, TRUE, TRUE, TRUE) + expect_warning(EstimationData(~Country + A, data = dat2, subset = filt), + "Some categories do not appear in the data: 'Country (Country): Australia', 'Country (Country): Fiji', 'A (A): 1'", fixed = TRUE) +})