Skip to content

Commit

Permalink
Merge pull request #28 from Displayr/DS-3784
Browse files Browse the repository at this point in the history
Fix typo and improve test for CombineVariableSetsAsBinary
  • Loading branch information
chrisfacer committed Jun 8, 2022
2 parents b77adfe + fa5916d commit 00a8ea0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions R/combinevariablesetsasbinary.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ questionToBinary <- function(x) {

if (question.type %in% c("PickAny", "PickAnyCompact")) {
# Identify and remove the NET column basedon the codeframe attribute
cf = attr(x, "codeframe")
cf <- attr(x, "codeframe")
if (!is.null(cf)) {
unique.codes = unique(unlist(cf))
net.cols = vapply(cf, isDefaultNet, FUN.VALUE = logical(1), unique.codes = unique.codes)
x[, !net.cols]
x <- x[, !net.cols]
}
return(x)
}
Expand Down
8 changes: 5 additions & 3 deletions tests/testthat/test-combinevariablesetsasbinary.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ attr(Q4.pepsi.max, "questiontype") <- "PickOne"
attr(Q4.pepsi.max, "dataset") <- "colas"

Q4.binary = CombineVariableSetsAsBinary(Q4)
Q4.binary = cbind(Q4.binary, "NET" = rep(TRUE, nrow(Q4.binary)))
attr(Q4.binary, "codeframe") <- list("Hate" = 1, "Dislike" = 2, "Neither like not dislike" = 3, "Love" = 4, "Like" = 5, "NET" = c(1,2,3,4,5))
attr(Q4.binary, "questiontype") <- "PickAny"
attr(Q4.binary, "dataset") <- "colas"

Expand Down Expand Up @@ -79,14 +81,14 @@ test_that("Many PickOnes are equivalent to a PickOneMulti", {

test_that("Combining PickOnes and Pick Any", {

expect_equal(Q4.binary, CombineVariableSetsAsBinary(Q4.binary.small, Q4.pepsi.light, Q4.pepsi.max), check.attributes = FALSE)
expect_equal(Q4.binary[, -ncol(Q4.binary)], CombineVariableSetsAsBinary(Q4.binary.small, Q4.pepsi.light, Q4.pepsi.max), check.attributes = FALSE)

})

test_that("Pick Any returns same data", {

expect_equal(CombineVariableSetsAsBinary(Q4.binary), Q4.binary, check.attributes = FALSE)
expect_equal(CombineVariableSetsAsBinary(Q4.binary, Q4.binary), Q4.binary, check.attributes = FALSE)
expect_equal(CombineVariableSetsAsBinary(Q4.binary), Q4.binary[, -ncol(Q4.binary)], check.attributes = FALSE)
expect_equal(CombineVariableSetsAsBinary(Q4.binary, Q4.binary), Q4.binary[, -ncol(Q4.binary)], check.attributes = FALSE)

})

Expand Down

0 comments on commit 00a8ea0

Please sign in to comment.