Skip to content

Better semantics for dataframeable objects #1676

Closed
@lionel-

Description

@lionel-

After thinking about tidyverse/purrr#179, I wonder if we could improve the semantics of dataframeable objects in bind_rows() by taking a vector viewpoint rather than a list viewpoint.

If we think about vectors, the current behaviour is not consistent because bind_rows() effectively binds columns together:

col_vectors <- list(
  a = c(1, 2),
  b = c(3, 4)
)

row_vectors <- list(
  c(a = 1, b = 3),
  c(a = 2, b = 4)
)
bind_rows(row_vectors)
#> Error: cannot convert object to a data frame

bind_rows(col_vectors)
#> Source: local data frame [2 x 2]
#>
#>       a     b
#>   (dbl) (dbl)
#> 1     1     3
#> 2     2     4

I think it'd be more intuitive to go the rbind() and cbind() way, and treat vectors differently depending on the direction of the binding. bind_rows() would require vectors with inner names and bind_cols() would require vectors with outer names.

Advantages:

The latter would add a lot of flexibility. bind_cols() and bind_rows() would accept indistinctly data frames, named vectors, and lists of data frames and named vectors.

cc @jennybc

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions