Skip to content

Commit

Permalink
Merge pull request #47 from randrescastaneda/row_order
Browse files Browse the repository at this point in the history
Row order fix
  • Loading branch information
zander-prinsloo authored Feb 26, 2024
2 parents 144231a + 2699753 commit d84b2e0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 27 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: joyn
Type: Package
Title: Tool for Diagnosis of Tables Joins and Complementary Join Features
Version: 0.1.6.9001
Version: 0.1.6.9002
Authors@R: c(person(given = "R.Andres",
family = "Castaneda",
email = "acastanedaa@worldbank.org",
Expand Down
31 changes: 7 additions & 24 deletions R/joyn-merge.R
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,8 @@ joyn <- function(x,
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
start_joyn <- Sys.time()
# copy objects if data.tables
if (any(class(x) == "data.table")) {
x <- copy(x)
}
if (any(class(y) == "data.table")) {
y <- copy(y)
}
x <- copy(x)
y <- copy(y)

## X and Y -----------
check_xy(x,y)
Expand All @@ -238,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
Expand Down Expand Up @@ -392,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
Expand Down Expand Up @@ -466,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)) {
Expand Down Expand Up @@ -523,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()
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-joyn.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit d84b2e0

Please sign in to comment.