From 3c188a9e672592c1ce60727bfc6c4757cc800b8c Mon Sep 17 00:00:00 2001 From: zander-prinsloo Date: Mon, 26 Feb 2024 14:18:18 -0500 Subject: [PATCH] fix order bug --- R/joyn-merge.R | 23 +++++------------------ tests/testthat/test-joyn.R | 4 ++-- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/R/joyn-merge.R b/R/joyn-merge.R index 4f15c4a7..001948ed 100644 --- a/R/joyn-merge.R +++ b/R/joyn-merge.R @@ -234,7 +234,6 @@ joyn <- function(x, y <- as.data.table(y) } - ## Modify BY when is expression --------- fixby <- check_by_vars(by, x, y) by <- fixby$by @@ -388,19 +387,6 @@ joyn <- function(x, #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Update x --------- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - # if (isTRUE(update_values) || isTRUE(update_NAs)) { - # var_use <- sub( - # pattern = "\\.y$", - # replacement = "", - # x = newyvars[ - # grepl( - # pattern = "\\.y$", - # x = newyvars - # ) - # ] - # ) - # } var_use <- NULL if (isTRUE(update_values) || isTRUE(update_NAs)) { var_use <- common_vars @@ -462,6 +448,11 @@ joyn <- function(x, .yreport = NULL) + if (sort) { + setorderv(x, by, na.last = na.last) + setattr(x, 'sorted', by) + } + ## Rename by variables ----- if (!is.null(fixby$xby)) { @@ -519,10 +510,6 @@ joyn <- function(x, x |> fselect(get(reportvar)) <- NULL } - if (sort) { - setorderv(x, by, na.last = na.last) - setattr(x, 'sorted', by) - } if (verbose == TRUE) { end_joyn <- Sys.time() diff --git a/tests/testthat/test-joyn.R b/tests/testthat/test-joyn.R index 1d33af34..2fd86a6d 100644 --- a/tests/testthat/test-joyn.R +++ b/tests/testthat/test-joyn.R @@ -568,8 +568,8 @@ test_that("different names in key vars are working fine", { ".joyn" = c("x & y", "x & y", "x", "y", "x", "x & y", "y", "y") ) - setorderv(dd, "id1", na.last = TRUE) - setattr(dd, 'sorted', "id1") + setorderv(dd, c("id1", "id2"), na.last = TRUE) + setattr(dd, 'sorted', c("id1", "id2")) expect_equal(df, dd)