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

Give list_all_vectors() and list_check_all_vectors() ptype and size arguments? #1582

Closed
DavisVaughan opened this issue Jun 30, 2022 · 3 comments · Fixed by #1714
Closed

Give list_all_vectors() and list_check_all_vectors() ptype and size arguments? #1582

DavisVaughan opened this issue Jun 30, 2022 · 3 comments · Fixed by #1714

Comments

@DavisVaughan
Copy link
Member

Because sometimes you want to check that a list is homogeneous in its type, or that all elements are the same size

tidyverse/dplyr#6300 (comment)
tidyverse/dplyr#6300 (comment)

The ptype arg might be a little tricky, because vec_assert(ptype =) is a little hard to formalize, and would need to be translated to C

@DavisVaughan
Copy link
Member Author

Or maybe we should implement list_all_size(x, size)

This would error if any element of x isn't a vector, but otherwise returns TRUE or FALSE. I feel like having it separated from the vector check would be useful, and it is faster than all(list_sizes(x) == 1L)

@DavisVaughan
Copy link
Member Author

Also useful here tidyverse/purrr#935

@DavisVaughan
Copy link
Member Author

DavisVaughan commented Oct 3, 2022

I think we have decided to implement:

  • list_all_size()
  • list_check_all_size()
    Since we already have list_sizes(), and this is a small wrapper around that to make it faster

The ptype check is a little strange, because do you really want list_check_all_vector(.ptype = double()) to enforce that all elements of the list are double? Or do you want them to be castable to double? Typically you just use vec_cast_common() here instead.

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 a pull request may close this issue.

1 participant