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

list_rbind overwrites data.frame name without warning if argument names_to is provided. #1120

Closed
cdolladille opened this issue Feb 22, 2024 · 1 comment

Comments

@cdolladille
Copy link

Hello,

I started using list_rbind() recently and found the following behavior : if arg names_to is provided with a value that is also a column name of the map output, then the column is overwritten.

c("t1", "t2") |> 
  rlang::set_names() |> 
  map(function(t_)
    data.frame(
      a = "expected value")
    ) |> 
  list_rbind()

Returns

a
expected value
expected value

c("t1", "t2") |> 
  rlang::set_names() |> 
  map(function(t_)
    data.frame(
      a = "expected value")
  ) |> 
  list_rbind(names_to = "a")

Returns

a
t1
t2

That may be an intended behavior but I can't find it documented in the ?list_rbind() help.
A message, a warning or a documentation could help?

Sorry if I missed the place where it's written, and thank you so much for developping all these consistent packages!

@hadley
Copy link
Member

hadley commented Jul 15, 2024

I think this is the behaviour we use consistently across the tidyverse — if you supply the name of a variable where output should go, it will overwrite any existing variable with that name. So that means we either have to document it everywhere (since otherwise folks will be confused when it's not documented), or nowhere. And since other functions that use the principle (like dplyr::mutate() and tidyr::separate_wider_*) don't document it, it looks like nowhere is the better better.

@hadley hadley closed this as completed Jul 15, 2024
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

No branches or pull requests

2 participants