Skip to content

Conversation

@olivroy
Copy link
Collaborator

@olivroy olivroy commented Jun 7, 2024

Summary

Fix #1697

The next time datasets are built, they will remove the readr::spec() attribute. Other datasets don't have this issue.

This is very minor, but it is just that object comparisons will be a little bit easier if we drop these classes.

I didn't rebuild the data as this is minor and this will naturally occur next time you need to add a dataset.

Strategy found in readr 1.3.0 changelog https://readr.tidyverse.org/news/index.html#tibble-data-frame-subclass-1-3-0

Basically, this aims to solve this.

v1 <- gtcars %>% dplyr::slice_head(n = 1, by = year) %>% dplyr::arrange(year)
v2 <- gtcars %>% dplyr::group_by(year) %>%  dplyr::slice_head(n = 1) %>% dplyr::ungroup()
all.equal(v1, v2)
#> [1] "Attributes: < Length mismatch: comparison on first 2 components >"                   
#> [2] "Attributes: < Component “class”: Lengths (4, 3) differ (string compare on first 3) >"
#> [3] "Attributes: < Component “class”: 3 string mismatches >"      

WIth the help of this PR, eventually when the datasets are redone,

# gtcars will eventually become gtcars2 with this PR.
gtcars2 <- gtcars[]
v3 <- gtcars2 %>% dplyr::slice_head(n = 1, by = year) %>% dplyr::arrange(year)
v4 <- gtcars2 %>% dplyr::group_by(year) %>%  dplyr::slice_head(n = 1) %>% dplyr::ungroup()
all.equal(v3, v4)
#> TRUE

Note that gtcars2 still has tbl_df class ("tbl_df" "tbl" "data.frame")

@olivroy olivroy changed the title Remove spec() from datasets Remove spec() from dataset generation scripts Jun 7, 2024
Copy link
Member

@rich-iannone rich-iannone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@rich-iannone rich-iannone merged commit 8e0b12e into rstudio:master Jun 7, 2024
@olivroy olivroy deleted the class branch June 13, 2024 23:08
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

Successfully merging this pull request may close these issues.

datasets should drop their (readr) spec attributes?

2 participants