From 113f7a5d7a374a0e86d7725cb1f011e4503f06b9 Mon Sep 17 00:00:00 2001 From: krassowski Date: Sat, 3 Apr 2021 20:37:47 +0100 Subject: [PATCH] Fix issue with encode_set when name conflicts are found --- NEWS.md | 3 ++- R/data.R | 2 +- tests/testthat/test-data.R | 12 +++++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index 3b4954d..e907621 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/data.R b/R/data.R index d39964f..1017b72 100644 --- a/R/data.R +++ b/R/data.R @@ -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 } diff --git a/tests/testthat/test-data.R b/tests/testthat/test-data.R index 105da83..27060c8 100644 --- a/tests/testthat/test-data.R +++ b/tests/testthat/test-data.R @@ -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( @@ -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') + ) })