Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collapse mm #61

Merged
merged 25 commits into from
May 23, 2024
Merged

Collapse mm #61

merged 25 commits into from
May 23, 2024

Conversation

zander-prinsloo
Copy link
Collaborator

Replace merge.data.table() with collapse::join() when match_type = "m:m"

All checks pass (excl. vignettes due to existing failures in DEV).

image

Copy link
Owner

@randrescastaneda randrescastaneda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @zander-prinsloo ,

Thank you so much for the improvement. There are a few things that are still not clear to me. Let's talk about them before merging.

Thanks.

Comment on lines 63 to 71
dt_1[dt_1[[reportvar]] == 4,
x.var] <- dt_1[dt_1[[reportvar]] == 4,
y.var,
with = FALSE]
#
dt_1[dt_1[[reportvar]] == 5,
x.var] <- dt_1[dt_1[[reportvar]] == 5,
y.var,
with = FALSE]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @zander-prinsloo , I don't understand this change. It is now making a deep copy rather than modifying by reference. What is the purpose of this change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@randrescastaneda , previously it was making a deep copy already using copy() and then modifying by reference after that. But you are right, this is not a sufficient improvement on what was done before. Let me propose a modification.

R/joyn-merge.R Outdated
Comment on lines 231 to 240
# ensure input names can be restored
byexp <- grep(pattern = "==?",
x = by,
value = TRUE)
xbynames <- trimws(gsub("([^=]+)(\\s*==?\\s*)([^=]+)",
"\\1",
byexp))
ybynames <- trimws(gsub("([^=]+)(\\s*==?\\s*)([^=]+)",
"\\3",
byexp))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happened with function fix_by_vars()?

R/joyn-merge.R Outdated Show resolved Hide resolved
R/joyn-merge.R Outdated
Comment on lines 449 to 485
# in output
if (any(grepl(pattern = "keyby", x = names(x)))) {
data.table::setnames(x,
old = names(x)[grepl(pattern = "keyby",
x = names(x))],
new = xbynames)
}


# Change names back for inputs------------------------------
if (any(grepl(pattern = "keyby", x = names(x_original)))) {

knames <- names(x_original)[grepl(pattern = "keyby",
x = names(x_original))]
knames <- knames[order(knames)]

data.table::setnames(x_original,
old = knames,
new = xbynames)
}

if (any(grepl(pattern = "keyby", x = names(y_original)))) {

knames <- names(y_original)[grepl(pattern = "keyby",
x = names(y_original))]
knames <- knames[order(knames)]

data.table::setnames(y_original,
old = knames,
new = ybynames)

if (all(names(y_original) %in% ynames)) {
colorderv(y_original,
neworder = ynames)
}
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When match_type is m:m this never hold because of the as.data.table() above, right? Is this by intention?


## Modify BY when is expression ---------
fixby <- check_by_vars(by, x, y)
by <- fixby$by

# Change names back on exit
# Change names back for inputs------------------------------
on.exit(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like this idea. excellent.

R/dplyr-joins.R Outdated
@@ -520,6 +595,19 @@ inner_join <- function(
dropreport <- args_check$dropreport

# Column names -----------------------------------
byexp <- grep(pattern = "==?",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these lines of code should be converted to a function that can be called everywhere. Right now, the same code is repeated in multiple places.

@zander-prinsloo
Copy link
Collaborator Author

@randrescastaneda Repetitive code made into a function. Merged with DEV and conflicts resolved. Please merge if you're happy.

Note seen below was introduced by masking functions, specifically unmask_joyn_fun_ns()

image

@randrescastaneda randrescastaneda merged commit d6c6e64 into DEV May 23, 2024
7 checks passed
@randrescastaneda randrescastaneda deleted the collapse_mm branch May 23, 2024 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants