Skip to content

Commit

Permalink
Fix #88 (workaround unexpected behavior when non-presence indicated b…
Browse files Browse the repository at this point in the history
…y NA)
  • Loading branch information
krassowski committed Jan 4, 2021
1 parent de0f165 commit 269fc41
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 1 deletion.
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Version 1.0.1

*In development*
2021-01-04

Bug fixes:
- Filtering by degree when using non-default mode and `intersections='all'` now correctly accounts for all observations (#89)
- Empty sets/groups are now correctly removed when filtering with a non-default mode (#90)
- Missing values are now converted to FALSE and a warning is issued to the user rather than causing an undefined behavior (#88)

# Version 1.0.0

Expand Down
5 changes: 5 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@ upset_data = function(
data[, non_logical] = sapply(data[, non_logical], as.logical)
}

if (any(is.na(data[, intersect]))) {
warning('Detected missing values in the columns indicating sets, coercing to FALSE')
data[, intersect][is.na(data[, intersect])] = FALSE
}

intersect_in_order_of_data = colnames(data)[colnames(data) %in% intersect]

non_sanitized_labels = intersect
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions tests/testthat/test-other-visual.R
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,26 @@ test_that("Empty sets are removed during filtering with non-default mode", {
)
)
)
})


test_that("Missing values are converted to FALSE", {
# see https://github.com/krassowski/complex-upset/issues/88
df = data.frame(
set_a = c(1, 1, 1, NA),
set_b = c(1, NA, NA, NA),
set_c = c(NA, NA, 4, NA),
set_d = c(NA, NA, NA, 1),
category = c("E", "F", "F", "G")
)

expect_warning(
upset(df, colnames(df)[1:2], min_degree=1),
regexp='Detected missing values in the columns indicating sets, coercing to FALSE'
)

expect_doppelganger(
"Degrees are filtered (min_degree=1) even if user indicated non-presence by NA",
upset(df, colnames(df)[1:2], min_degree=1)
)
})

0 comments on commit 269fc41

Please sign in to comment.