Skip to content

Commit

Permalink
add style_na_if to style vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanzomorrodi committed Jun 29, 2024
1 parent a912157 commit 2c0561b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
12 changes: 3 additions & 9 deletions R/glimpse.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ format_glimpse.default <- function(x, ...) {
paste0("<", class(x)[[1]], "[", dims_out, "]>")
} else {
out <- format(x, trim = TRUE, justify = "none")
out[is.na(x)] <- crayon_red(NA)

out
style_na_if(out, is.na(x))
}
}

Expand All @@ -173,9 +171,7 @@ format_glimpse.list <- function(x, ..., .inner = FALSE) {
#' @export
format_glimpse.character <- function(x, ...) {
out <- encodeString(as.character(x), quote = '"')
out[is.na(x)] <- crayon_red(NA)

out
style_na_if(out, is.na(x))
}

#' @export
Expand All @@ -185,7 +181,5 @@ format_glimpse.factor <- function(x, ...) {
} else {
out <- format(x, trim = TRUE, justify = "none")
}
out[is.na(x)] <- crayon_red(NA)

out
style_na_if(out, is.na(x))
}
5 changes: 5 additions & 0 deletions R/styles.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ style_na <- function(x) {
crayon_red(x)
}

style_na_if <- function(x, p) {
x[p] <- style_na("NA")
x
}

#' @details
#' `style_neg()` is affected by the `pillar.neg` [option][pillar_options].
#'
Expand Down

0 comments on commit 2c0561b

Please sign in to comment.