Skip to content

Commit

Permalink
DS-3781: Fix bug when stacked variable labels were identical (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinCCYap committed Jul 6, 2022
1 parent d66383a commit 3c046a2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: flipData
Type: Package
Title: Functions for extracting and describing data
Version: 1.6.3
Version: 1.6.4
Author: Displayr <opensource@displayr.com>
Maintainer: Displayr <opensource@displayr.com>
Description: Functions for extracting data from formulas and
Expand Down
6 changes: 6 additions & 0 deletions R/stacking.R
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,9 @@ stackedValueAttributes <- function(group.ind, input.value.attributes)
# halfway into a word or number.
getCommonPrefix <- function(nms, whole.words = FALSE)
{
if (allIdentical(nms))
return(nms[1])

common_prefix <- ""
for (i in 1:min(nchar(nms)))
{
Expand Down Expand Up @@ -1283,6 +1286,9 @@ getCommonSuffixTwoNames <- function(nms)
# halfway into a word or number.
getCommonSuffix <- function(nms, whole.words = FALSE)
{
if (allIdentical(nms))
return(nms[1])

common_suffix <- ""
for (i in 1:min(nchar(nms)))
{
Expand Down
Binary file added inst/testdata/cola20.sav
Binary file not shown.
12 changes: 12 additions & 0 deletions tests/testthat/test-stacking.R
Original file line number Diff line number Diff line change
Expand Up @@ -702,3 +702,15 @@ test_that("DS-3758: special characters at end of variable names", {
specify.by = "Variable",
manual.stacking = c("Q1_F_c@,Q1_E_c1@,Q1_D_c@,Q1_C_c1@,Q1_A_c@,Q1_B_c1@")), NA)
})

# cola20.sav has variables with the same labels, e.g. Q10_A, Q10_A_2.
test_that("DS-3781: identical variable labels", {
result <- StackData(findInstDirFile("cola20.sav"),
stack.with.common.labels = "Disabled",
specify.by = "Variable",
manual.stacking = c("Q10_A,Q10_A_2", "Q10_B,Q10_B_2"))
expect_equal(unname(result$stacked.data.set.metadata$variable.labels[1]),
"Sometimes I drink cola that is bought by my friends or family")
expect_equal(unname(result$stacked.data.set.metadata$variable.labels[2]),
"Three words only")
})

0 comments on commit 3c046a2

Please sign in to comment.