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

Should miscellaneous attributes be preserved in vec_c/rbind()? #1783

Open
DavisVaughan opened this issue Feb 9, 2023 · 1 comment
Open

Comments

@DavisVaughan
Copy link
Member

From tidyverse/dplyr#6705 with columns during bind_rows()

library(vctrs)

x <- structure(1, label = "foo")
y <- structure(2, label = "bar")

vec_c(x, y)
#> [1] 1 2

x <- data_frame(x = x)
y <- data_frame(x = y)

vec_rbind(x, y)$x
#> [1] 1 2

Possibly retaining the attributes of the first input?

My heart says no, and that you should create a custom class that knows about label if you want this.

@netique
Copy link

netique commented Oct 26, 2024

I vote for keeping the attributes intact. Or is there any easy way how to turn vectors of any class into vctrs vectors that know about custom attribute(s)? For my usecase, I want to store "label" attribute of columns in tibble and I don't want to lose it on every list_rbind() or bind_rows() call 😔. I tried to create vcrts "analogues" of doubles, integers, characters with the simple approach below, but failed miserably on factors...

new_vctr(x, label = label, class = "labelled", inherit_base_type = TRUE)

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