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

error with cross_d when a list of same-type vectors is in the .l argument #327

Closed
wepelham3 opened this issue May 19, 2017 · 2 comments
Closed
Labels
feature a feature request or enhancement vctrs ♣️
Milestone

Comments

@wepelham3
Copy link

If I have a list of vectors as one of the elements in .l argument passed to cross_d, I get an error when the vectors are all of the same type.

Appears like the elements of a series of same-type vectors are getting appended together into one long vector during the process of simplifying to a data frame, which causes the error?

library(purrr)

to.cross1 <- list(x = c("apple", "banana"),
                  y = list(c("1", "2", "3"), c("a", "b")))

# error
cross_d(to.cross1)

# ------------------------------------------------------

to.cross2 <- list(x = c("apple", "banana"),
                  y = list(list("1", "2", "3"), list("a", "b")))

# working, but now y is a list of lists rather than a list of vectors
cross_d(to.cross2)

# ------------------------------------------------------

# just like first example, but with the two vectors in y being of different types
to.cross3 <- list(x = c("apple", "banana"),
                  y = list(c("1", "2", "3"), c(3.33, 5.55)))

# working, and y is a list of vectors
cross_d(to.cross3)

@lionel-
Copy link
Member

lionel- commented Jul 19, 2017

This is a difficult problem because we're trying to be helpful and simplify lists of scalar vectors where possible. This doesn't always work out, hence the inconsistent (in appearance) results.

It feels like this problem is connected to the issue #256, i.e. we need a specification for the types of the transposed columns.

@hadley hadley added the feature a feature request or enhancement label Feb 5, 2018
@lionel- lionel- added this to the vctrs milestone Nov 30, 2018
@lionel-
Copy link
Member

lionel- commented Jun 5, 2020

We'll likely deprecate cross() and cross_df() in favour of tidyr::expand_grid(). See #768.

@lionel- lionel- closed this as completed Jun 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement vctrs ♣️
Projects
None yet
Development

No branches or pull requests

3 participants