Skip to content

Commit

Permalink
Fix issue with encode_set when name conflicts are found
Browse files Browse the repository at this point in the history
  • Loading branch information
krassowski committed Apr 3, 2021
1 parent cb9c515 commit 113f7a5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
2021-04-03

Bux fixes:
- [critical] fixed display order of labels when using encode_sets=TRUE
- [critical] fixed display order of labels when using `encode_sets=TRUE` #110
- encoding of set names will now properly work around name conflicts #110

Major improvements:
- manually specified intersections will now display empty intersections and non-exclusive intersections correctly #109
Expand Down
2 changes: 1 addition & 1 deletion R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ encode_names = function(variables_names, avoid) {
as.character(rank(variables_names)),
function (name) {
while (any(name %in% avoid)) {
name = name + 'x'
name = paste0(name, 'x')
}
name
}
Expand Down
12 changes: 11 additions & 1 deletion tests/testthat/test-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ test_that("upset_data() works with a tibble or a data.table", {
test_that("labels retain proper order when encoded", {
expect_equal(
unname(encode_names(c('a', 'b', 'c'), avoid=c())),
c( '1', '2', '3')
c('1', '2', '3')
)

expect_equal(
Expand All @@ -574,4 +574,14 @@ test_that("labels retain proper order when encoded", {
unname(encode_names(c('c', 'a', 'b'), avoid=c())),
c('3', '1', '2')
)

expect_equal(
unname(encode_names(c('a', 'b', 'c'), avoid=c('1'))),
c('1x', '2', '3')
)

expect_equal(
unname(encode_names(c('c', 'a', 'b'), avoid=c('1'))),
c('3', '1x', '2')
)
})

0 comments on commit 113f7a5

Please sign in to comment.