Skip to content

Commit

Permalink
DS-3758: fix bug with special characters at the end of variable names (
Browse files Browse the repository at this point in the history
…#31)

* Prevent data.frame from renaming variables with special characters [revdep skip]

* Add test [revdep skip]
  • Loading branch information
JustinCCYap committed Jul 4, 2022
1 parent c60132e commit 8519d49
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 4 deletions.
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.1
Version: 1.6.2
Author: Displayr <opensource@displayr.com>
Maintainer: Displayr <opensource@displayr.com>
Description: Functions for extracting data from formulas and
Expand Down
2 changes: 1 addition & 1 deletion R/mergedatasetsbycase.R
Original file line number Diff line number Diff line change
Expand Up @@ -1859,7 +1859,7 @@ mergedDataSet <- function(data.sets, matched.names, merged.names,
"Consider omitting variables or only keeping combined variables that contain input variables from a few data sets.")
merged.data.set[[i]] <- v
}
merged.data.set <- data.frame(merged.data.set)
merged.data.set <- data.frame(merged.data.set, check.names = FALSE)
names(merged.data.set) <- merged.names

mergesrc.name <- uniqueName("mergesrc", names(merged.data.set), "_")
Expand Down
2 changes: 1 addition & 1 deletion R/mergedatasetsbyvariable.R
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ doMergeByVariable <- function(data.sets, matched.cases.matrix,
}
}
names(merged.data.set.variables) <- merged.data.set.variable.names
data.frame(merged.data.set.variables)
data.frame(merged.data.set.variables, check.names = FALSE)
}

#' @param id.variable.names See data dictionary.
Expand Down
2 changes: 1 addition & 1 deletion R/stacking.R
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,7 @@ stackedDataSet <- function(input.data.set, input.data.set.metadata,
names(stacked.data.set))]] <- observation
}

data.frame(stacked.data.set)
data.frame(stacked.data.set, check.names = FALSE)
}

stackedVariableName <- function(group.ind, input.variable.names, taken.names)
Expand Down
Binary file added inst/testdata/cola19.sav
Binary file not shown.
9 changes: 9 additions & 0 deletions tests/testthat/test-stacking.R
Original file line number Diff line number Diff line change
Expand Up @@ -693,3 +693,12 @@ test_that("stackedValueAttributes", {
expect_equal(stackedValueAttributes(1:2, val.attrs),
structure(1:3, .Names = c("A", "B", "C")))
})


# cola19.sav was created from cola.sav by appending @ to the end of the variable names of the 1st question
test_that("DS-3758: special characters at end of variable names", {
expect_error(StackData(findInstDirFile("cola19.sav"),
stack.with.common.labels = "Disabled",
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)
})

0 comments on commit 8519d49

Please sign in to comment.