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

bind_rows should have col_type argument #3278

Closed
hadley opened this issue Jan 1, 2018 · 7 comments
Closed

bind_rows should have col_type argument #3278

hadley opened this issue Jan 1, 2018 · 7 comments
Labels
feature a feature request or enhancement

Comments

@hadley
Copy link
Member

hadley commented Jan 1, 2018

So you could prespecify the types of the columns. For performance and safety.

@krlmlr
Copy link
Member

krlmlr commented Jan 17, 2018

I'm not sure, we can already do:

tibble(
  x = character(), y = integer(), z = list()
) %>%
  bind_rows(a, b)

to presprecify column types. Do we need to implement a safer coercion logic?

@krlmlr krlmlr added feature a feature request or enhancement data frame labels Jan 17, 2018
@hadley
Copy link
Member Author

hadley commented Jan 17, 2018

I think so - this is about providing a common interface across read_csv(), convert_types(), map_c() etc.

@RichardJActon
Copy link

As I just recently mentioned in #1485 I think it would be useful to have an option in bind_rows that instead of coercing factors to character vectors lets you specify that you want a new factor with levels from both of the original dataframes/tbls so you know don't have to manually make new factors. However, letting you specify types would likely also solve this, depending on how it handled factors with different levels in the source dfs.

Although I suppose you would probably want warning if you are altering factor levels as a result of a bind, so maybe an explicit relevel-factors=TRUE / refactor=TRUE like argument should be required to suppress a warning about releveling factors.

Perhaps a short-form like inherit-col-types that lets you specify that you want the same datatypes as the original dfs (assuming all the columns have matching types) would be handy?

@mkoohafkan
Copy link

Could this a different approach to tibble's as_tibble_row? If we could specify certain column types as "list" in bind_rows it would probably override the need for as_tibble_row for most use cases.

@romainfrancois
Copy link
Member

@hadley is this vctrs::vec_rbind ?

@hadley
Copy link
Member Author

hadley commented Dec 18, 2018

Yup

@hadley hadley closed this as completed Dec 18, 2018
@lock
Copy link

lock bot commented Jun 16, 2019

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Jun 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

5 participants