From 0a9f8b016e9033ba023006dcc5f4ea6ba499dd88 Mon Sep 17 00:00:00 2001 From: zander-prinsloo Date: Wed, 31 Jul 2024 23:31:29 -0400 Subject: [PATCH 1/3] filter rows before updating values --- R/joyn-merge.R | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/R/joyn-merge.R b/R/joyn-merge.R index 4eb18490..e0d29686 100644 --- a/R/joyn-merge.R +++ b/R/joyn-merge.R @@ -385,25 +385,6 @@ joyn <- function(x, ) - #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - # Update jn --------- - #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - var_use <- NULL - if (isTRUE(update_NAs) || isTRUE(update_values)) { - var_use <- common_vars - } - - if (isTRUE(update_NAs || update_values) & length(var_use) > 0 ) { - - jn <- update_na_values(dt = jn, - var = var_use, - reportvar = reportvar, - suffixes = suffixes, - rep_NAs = update_NAs, - rep_values = update_values - ) - - } #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Filter rows - `keep` --------- @@ -430,6 +411,28 @@ joyn <- function(x, } + #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + # Update jn --------- + #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + var_use <- NULL + if (isTRUE(update_NAs) || isTRUE(update_values)) { + var_use <- common_vars + } + + if (isTRUE(update_NAs || update_values) & length(var_use) > 0 ) { + # filter_var <- jn |> + # fselect(get(reportvar)) + #print(filter_var) + jn <- update_na_values(dt = jn, + var = var_use, + reportvar = reportvar, + suffixes = suffixes, + rep_NAs = update_NAs, + rep_values = update_values + ) + + } + ### common vars ---------- if (isFALSE(keep_common_vars)) { From 2566a8999d09def89f3420aa4448a2ff54178ffe Mon Sep 17 00:00:00 2001 From: zander-prinsloo Date: Wed, 31 Jul 2024 23:31:47 -0400 Subject: [PATCH 2/3] test update vals works for left join, filter rows --- tests/testthat/test-joyn.R | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/testthat/test-joyn.R b/tests/testthat/test-joyn.R index 1a799a19..5ccc2f04 100644 --- a/tests/testthat/test-joyn.R +++ b/tests/testthat/test-joyn.R @@ -855,3 +855,30 @@ test_that("joyn() - input data unchanged", { }) +test_that("update_values still filters rows for left joins", { + + x <- data.frame(id = 1:5, + a = 1:5, + b = 2:6) + y <- data.frame(id = c(1, 11, 2, 12, 5), + a = 11:15, + b = 12:16) + + # for data.table + j1 <- joyn(x = qDT(x), + y = qDT(y), + by = "id", + keep = "left", + update_values = TRUE) + + j2 <- joyn(x = x, + y = y, + by = "id", + keep = "left", + update_values = TRUE) + + expect_true(all(j1$id %in% x$id)) + expect_true(all(j2$id %in% x$id)) + +}) + From 9e4f50de3b28a261f5d9f131cc01f4d3480638a5 Mon Sep 17 00:00:00 2001 From: zander-prinsloo Date: Thu, 1 Aug 2024 09:48:25 -0400 Subject: [PATCH 3/3] Increment version number to 0.2.2.9001 --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index f4cd46b0..5134a09f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: joyn Type: Package Title: Tool for Diagnosis of Tables Joins and Complementary Join Features -Version: 0.2.2.9000 +Version: 0.2.2.9001 Authors@R: c(person(given = "R.Andres", family = "Castaneda", email = "acastanedaa@worldbank.org",