Skip to content

Commit

Permalink
DS-2626: Fix last two commits
Browse files Browse the repository at this point in the history
  • Loading branch information
chschan committed Jan 30, 2020
1 parent 61ccdbb commit 0d53793
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
6 changes: 4 additions & 2 deletions R/estimationdata.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
11 changes: 7 additions & 4 deletions tests/testthat/test-estimationdata.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})



0 comments on commit 0d53793

Please sign in to comment.