Skip to content

Plan for flatten(), simplify() and friends #900

@hadley

Description

@hadley

I suggest we at least we mark as_vector(), simplify(), simplify_all(), flatten(), and flatten_*() as questioning and remove from the function index. The semantics of these functions are not super clear, and I'm not sure it's worth completely nailing them down because many of the problems they were originally designed to solve have moved into tidyr. Their use in their purrr docs reveals few compelling uses cases:

  • as_vector() is only used in its own examples.

  • simplify() (a version of as_vector() that returns x if it can simplify) isn't used at all.

  • simplify_all() is used with the output of transpose(). The most compelling use case is with safely() to get lists of error and results. But I suspect we could tackle this a different way, perhaps with a list_transpose() inspired by the work we've done in unnest_longer()/unnest_wider() or possibly powered by vec_simplify().

  • flatten() is only used in its own examples. I can see flatten() being useful in conjunction with map() but it might be easier to create the flat_map() functions directly.

Long term, if we do discover that flatten() and simplify() are useful enough to bother fully fleshing out their semantics, I'd suggest deprecating them and introducing new list_flatten() and list_simplify().

Additionally, it might be worth deprecating flatten_dfc() and flatten_dfr() as they have poor semantics (#648, #757). They are similar to both dplyr::bind_rows(x) and vctrs::vec_rbind(!!!x). If we think it's unappealing to recommend a vctrs function we could add list_rbind <- function(x) vctrs::vec_rbind(!!!x) (and similar for list_cbind()). I think we'd probably require individual elements to be data frames.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions