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

Join without merge #240

Merged
merged 29 commits into from
Jul 1, 2021
Merged

Join without merge #240

merged 29 commits into from
Jul 1, 2021

Conversation

mgirlich
Copy link
Collaborator

@mgirlich mgirlich commented May 7, 2021

The main goal was to ensure correct handling of a named by in the joins and to ensure correct column names also in edge cases. Now, left/right/inner_join() always use [.data.table(). Unfortunately, this makes the translation of left_join() longer as it now usually requires calls to both, setcolorder() and setnames().

Could make use of step_setnames() added in PR #241.

Relates to #239. Fixes #243 and fixes #222 and fixes #198.

R/step-join.R Outdated Show resolved Hide resolved
R/step-join.R Show resolved Hide resolved
R/step-join.R Outdated Show resolved Hide resolved
R/step-join.R Outdated Show resolved Hide resolved

step_call(parent,
if (is.integer(col_order)) {
if (all(col_order == seq_along(col_order))) {
Copy link
Member

Choose a reason for hiding this comment

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

I think that should use identical() since == is vectorised?

Copy link
Member

Choose a reason for hiding this comment

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

And maybe move the check until after handling the different types? i.e. if (identical(vars, x$vars)) ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The check doesn't work like this as the data.table can have duplicate names. And this actually happens in merge():

library(data.table)

merge(
  data.table(x = 1, y = 2),
  data.table(x = 1, y = 3, y.x = 4),
  by = "x"
)
#> Warning in merge.data.table(data.table(x = 1, y = 2), data.table(x = 1, : column
#> names 'y.x' are duplicated in the result
#>    x y.x y.y y.x
#> 1: 1   2   3   4

Created on 2021-05-11 by the reprex package (v2.0.0)

And this then also happens in the new implementation of full_join()

R/step-join.R Outdated Show resolved Hide resolved
R/step-join.R Outdated Show resolved Hide resolved
NEWS.md Show resolved Hide resolved
@mgirlich mgirlich mentioned this pull request May 25, 2021
10 tasks
NEWS.md Show resolved Hide resolved
@mgirlich mgirlich merged commit 5465087 into tidyverse:master Jul 1, 2021
switch(x$style,
full = call2("merge", lhs, rhs, all = TRUE, by.x = x$on$x, by.y = x$on$y, allow.cartesian = TRUE),
left = call2("[", lhs, rhs, on = on, allow.cartesian = TRUE),
inner = call2("[", lhs, rhs, on = on, nomatch = NULL),
Copy link
Member

Choose a reason for hiding this comment

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

@mgirlich does this deliberately not include allow.cartesian = TRUE? Or was it omitted by accident?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm pretty sure this was by accident.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants