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

crossing behaves differently with vectors and tibbles #490

Closed
alexpghayes opened this issue Aug 27, 2018 · 3 comments

Comments

@alexpghayes
Copy link

commented Aug 27, 2018

It appears that duplicate elements of vectors are dropped before generating permutations, but duplicate elements of tibbles are not. This is especially concerning in the case of vectors because it is likely to introduce silent errors when calculating permutation statistics (i.e. some of the data just won't be used in the calculation).

library(tidyverse)

x <- c(1, 2, 2)
z <- tibble(d = x)

y <- tibble(b = 4:6)

crossing(x, y)
#> # A tibble: 6 x 2
#>       x     b
#>   <dbl> <int>
#> 1     1     4
#> 2     1     5
#> 3     1     6
#> 4     2     4
#> 5     2     5
#> 6     2     6

crossing(y, z)
#> # A tibble: 9 x 2
#>       b     d
#>   <int> <dbl>
#> 1     4     1
#> 2     4     2
#> 3     4     2
#> 4     5     1
#> 5     5     2
#> 6     5     2
#> 7     6     1
#> 8     6     2
#> 9     6     2

Created on 2018-08-26 by the reprex package (v0.2.0).

@hadley

This comment has been minimized.

Copy link
Member

commented Jan 4, 2019

I'm reasonably certain this is a bug, but probably needs a bit more thinking and consideration of existing code and test cases.

@hadley

This comment has been minimized.

Copy link
Member

commented Feb 25, 2019

Looking crossing() now, the semantics look very blurry. I suspect the whole idea needs to be rethought, probably as part of #557 and #448.

@hadley

This comment has been minimized.

Copy link
Member

commented Feb 28, 2019

No difference in the dev version:

library(tidyr)
library(tibble)

x <- c(1, 2, 2)
y <- tibble(b = 4:6)

crossing(x, y)
#> # A tibble: 6 x 2
#>       x   y$b
#>   <dbl> <int>
#> 1     1     4
#> 2     1     5
#> 3     1     6
#> 4     2     4
#> 5     2     5
#> 6     2     6
crossing(df = tibble(x = x), y)
#> # A tibble: 6 x 2
#>    df$x   y$b
#>   <dbl> <int>
#> 1     1     4
#> 2     1     5
#> 3     1     6
#> 4     2     4
#> 5     2     5
#> 6     2     6

Created on 2019-02-28 by the reprex package (v0.2.1.9000)

We will need to consider automatically unpacking unnamed tibbles.

hadley added a commit that referenced this issue Feb 28, 2019
Including creating new low-level expand_grid(). Is likely to have some changes to revdeps, but they should be because we're making tidyr more consistent with other tidyverse functions so they should be worth it.

Fixes #557. Fixes #490.
@hadley hadley closed this in #561 Mar 2, 2019
hadley added a commit that referenced this issue Mar 2, 2019
Including creating new low-level expand_grid(). Is likely to have some changes to revdeps, but they should be because we're making tidyr more consistent with other tidyverse functions so they should be worth it.

Fixes #557. Fixes #490.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.