-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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() using tibbles with attributes loses attributes #3259
Comments
Thinking about what might be coming in the future, what if |
Thanks. Calling |
By "symmetric" is that meaning keeping all custom attributes for each argument? Or just specifically attributes of the second argument, and not the first? If it's the former, I can think of edge cases where the first and second arguments have attributes of the same name but with different data. Perhaps in this case the first argument should have precedence. I assume this should propagate to library(dplyr)
iris_tbl1 <- as_tibble(iris)
iris_tbl2 <- as_tibble(iris)
attr(iris_tbl1, "my_attr") <- "important thing 1"
attr(iris_tbl2, "my_attr") <- "important thing 2"
attr(iris_tbl2, "my_attr2") <- "attr unique to 2"
# bind_cols() keeps attributes of the first object ONLY
bind_cols(iris_tbl1, iris_tbl2) %>%
attributes()
#> $row.names
#> ...truncated
#>
#> $class
#> [1] "tbl_df" "tbl" "data.frame"
#>
#> $my_attr
#> [1] "important thing 1"
#>
#> $names
#> [1] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width"
#> [5] "Species" "Sepal.Length1" "Sepal.Width1" "Petal.Length1"
#> [9] "Petal.Width1" "Species1"
# bind_rows() of course loses all custom attributes
bind_rows(iris_tbl1, iris_tbl2) %>%
attributes()
#> $names
#> [1] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width"
#> [5] "Species"
#>
#> $row.names
#> ...truncated
#>
#> $class
#> [1] "tbl_df" "tbl" "data.frame" |
"Symmetric" means that the logic decides which attributes are inherited from which arguments, and that the attributes of |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Related to #3429? |
Duplicate of #2457 and will be resolved by vctrs. |
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/ |
I assume this is very similar to #2457.
Using
bind_rows()
on two tibbles where either one has extra attributes removes all extra attributes. Perhaps an approach similar to #1692 can be taken where the attributes of the first are kept? Ideally I would likebind_rows()
to be generic but I've read all the problems associated with that.My use case is in
tibbletime
. Myprint.tbl_time()
method relies on one of the attributes. Because thetbl_time
class is kept after usingbind_rows()
, but the attributes are lost, this causes problems. It causes other problems too, but this shows up immediately.Session info
The text was updated successfully, but these errors were encountered: