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

Attributes of non key-value columns in spread #451

Closed
stephematician opened this issue May 7, 2018 · 2 comments
Closed

Attributes of non key-value columns in spread #451

stephematician opened this issue May 7, 2018 · 2 comments

Comments

@stephematician
Copy link

Is there a reason that column attributes are voided when using spread()? e.g.

D <- data.frame(x=c(1,2), y=c('A','B'), z=c(6,7))
attributes(D$x) <- list(a='b')
sapply(spread(D, y, z), attributes)

Gives:

$x
NULL

$A
NULL

$B
NULL
@batpigandme
Copy link
Contributor

Hi,

So, I believe this is related to the handling of attributes in dplyr as well. On that front, there are several issues open that might be worth looking at:
tidyverse/dplyr#3259
tidyverse/dplyr#2752

@hadley
Copy link
Member

hadley commented Jan 4, 2019

Because attributes aren't preserved when subsetting:

df <- data.frame(x=c(1,2), y=c('A','B'), z=c(6,7))
attributes(df$x) <- list(a='b')
attributes(df[1:2, ]$x)
#> NULL

Created on 2019-01-04 by the reprex package (v0.2.1.9000)

@hadley hadley closed this as completed Jan 4, 2019
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

3 participants