Skip to content

Commit

Permalink
Merge pull request #37 from katelynqueen98/patch-1
Browse files Browse the repository at this point in the history
Fix issue with not sorting columns for reduced vars
  • Loading branch information
malcolmbarrett committed May 22, 2024
2 parents 3f8029a + aac8b7c commit 8bc6314
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions R/super_partition.R
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,10 @@ super_partition <- function(full_data,

# sort reduced var rows
reduced_var_rows <- grep(x, part_master$mapping_key$variable)
part_master$mapping_key$variable[reduced_var_rows] <-
part_master$mapping_key$variable[reduced_var_rows][gtools::mixedorder(part_master$mapping_key$variable[reduced_var_rows])]
new_order <- gtools::mixedsort(part_master$mapping_key$variable[reduced_var_rows])
small <- part_master$mapping_key[reduced_var_rows, ]
small <- small[match(new_order, small$variable), ]
part_master$mapping_key[reduced_var_rows, ] <- small

# match names between mapping_key and reduced_data
part_master$reduced_data <- part_master$reduced_data[, match(part_master$mapping_key$variable, colnames(part_master$reduced_data))]
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-super-partition-objects.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ test_that("dimensions are consistent", {
expect_equal(nrow(map_key), 4)
expect_equal(nrow(reduced_map), 3)
map_lengths <- purrr::map_int(map_key[["mapping"]], length)
expect_true(all(map_lengths == c(1, 2, 2, 3)))
expect_true(all(map_lengths == c(1, 3, 2, 2)))
index_lengths <- purrr::map_int(map_key[["indices"]], length)
expect_true(all(index_lengths == map_lengths))

Expand Down

0 comments on commit 8bc6314

Please sign in to comment.