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

feat: Show missing values in red in glimpse() #662

Merged
merged 6 commits into from
Jul 7, 2024

Conversation

ryanzomorrodi
Copy link
Contributor

Changes to make glimpse show NAs in red., as brought up in #658.

Copy link
Member

@krlmlr krlmlr left a comment

Choose a reason for hiding this comment

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

Thanks! Can you please add tests? There are some snapshot tests that also write the ANSI sequences to the snapshot file.

R/glimpse.R Outdated
@@ -144,7 +144,10 @@ format_glimpse.default <- function(x, ...) {
dims_out <- paste0(dims, collapse = " x ")
paste0("<", class(x)[[1]], "[", dims_out, "]>")
} else {
format(x, trim = TRUE, justify = "none")
out <- format(x, trim = TRUE, justify = "none")
Copy link
Member

Choose a reason for hiding this comment

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

This looks like an opportunity to remove the negation from the if condition.

R/glimpse.R Outdated
}
out[is.na(x)] <- crayon_red(NA)
Copy link
Member

Choose a reason for hiding this comment

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

This looks like a pattern that we use in many places: assign a red NA string to a vector where another vector has NA values.

  • Should this be a function?
  • Should this be crayon_red(NA) or crayon_red(out[is.na(x)]) instead?

@krlmlr krlmlr changed the title make NAs show up red in glimpse feat: Show missing values in red in glimpse() Jun 29, 2024
@ryanzomorrodi
Copy link
Contributor Author

ryanzomorrodi commented Jun 29, 2024

I added tests and a style_na_if function. I didn't use crayon_red(out[is.na(x)]) because I was concerned about encodeString adding quotes to NA, but it seems like it just transforms it to a character, so it seems like either would work.

@krlmlr krlmlr merged commit 106a50d into r-lib:main Jul 7, 2024
18 checks passed
@krlmlr
Copy link
Member

krlmlr commented Jul 7, 2024

Thanks!

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.

2 participants