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

datasets should drop their (readr) spec attributes? #1697

Closed
olivroy opened this issue Jun 6, 2024 · 2 comments · Fixed by #1699
Closed

datasets should drop their (readr) spec attributes? #1697

olivroy opened this issue Jun 6, 2024 · 2 comments · Fixed by #1699

Comments

@olivroy
Copy link
Collaborator

olivroy commented Jun 6, 2024

class(gtcars)
#> [1] "spec_tbl_df" "tbl_df"      "tbl"         "data.frame" 

Isn't really useful.

attr(gtcars, "spec")
attr(gtcars, "spec") <- NULL
@olivroy
Copy link
Collaborator Author

olivroy commented Jun 6, 2024

readr also adds the spec_tbl_df class to data frame. Would need to be stripped too?

@olivroy
Copy link
Collaborator Author

olivroy commented Jun 6, 2024

@rich-iannone from readr docs : using gtcars <- gtcars[] can acheive this!

readr 1.3.0 returns results with a spec_tbl_df subclass. This differs from a regular tibble only that the spec attribute (which holds the column specification) is lost as soon as the object is subset (and a normal tbl_df object is returned).

Historically tbl_df’s lost their attributes once they were subset. However recent versions of tibble retain the attributes when subetting, so the spec_tbl_df subclass is needed to ensure the previous behavior.

This should only break compatibility if you are explicitly checking the class of the returned object. A way to get backwards compatible behavior is to call subset with no arguments on your object, e.g. x[].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment