nathaneastwood / poorman

A poor man's dependency free grammar of data manipulation
https://nathaneastwood.github.io/poorman/
Other
338 stars 15 forks source link

Small fix for semi_join() and anti_join(): always end with data.frame, not a vector #49

Closed msberends closed 3 years ago

msberends commented 4 years ago

You might want to check all of your code for x[y, z] and x[y, ] cases, and replace them with x[y, z, drop = FALSE] and x[y, , drop = FALSE] to prevent that you will end up with a vector if z has length one.

nathaneastwood commented 4 years ago

Hey thanks for the PR! Do you have a working example for this at all? I agree that this is a needed fix, I just want to add some tests as well so it doesn't somehow get reintroduced in the future.

Also, I updated master so in future PRs will refer you to the git commit standards for the project.

msberends commented 4 years ago

Yes, I ran into trouble using an anti join last week. I’ll look it up!

msberends commented 3 years ago

Here it is:

tbl1 <- data.frame(a = sample(rep(LETTERS[1:3], 10)), 
                   stringsAsFactors = FALSE)
tbl2 <- data.frame(a = LETTERS[1:3],
                   b = colours()[1:3], 
                   stringsAsFactors = FALSE)

class(poorman::semi_join(tbl1, tbl2))
#> [1] "character"
class(dplyr::semi_join(tbl1, tbl2))
#> [1] "data.frame"