Skip to content

Commit 89a7613

Browse files
authored
Update missing value warning (#5269)
* Update message * Update tests
1 parent a076a10 commit 89a7613

File tree

10 files changed

+23
-17
lines changed

10 files changed

+23
-17
lines changed

R/geom-path.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ GeomPath <- ggproto("GeomPath", Geom,
140140
data <- data[kept, ]
141141

142142
if (!all(kept) && !params$na.rm) {
143-
cli::cli_warn("Removed {sum(!kept)} row{?s} containing missing values ({.fn {snake_class(self)}}).")
143+
cli::cli_warn(paste0(
144+
"Removed {sum(!kept)} row{?s} containing missing values or values ",
145+
"outside the scale range ({.fn {snake_class(self)}})."
146+
))
144147
}
145148

146149
data

R/geom-sf.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,10 @@ sf_grob <- function(x, lineend = "butt", linejoin = "round", linemitre = 10,
176176
remove[is_other] <- detect_missing(x, c(GeomPolygon$required_aes, GeomPolygon$non_missing_aes))[is_other]
177177
if (any(remove)) {
178178
if (!na.rm) {
179-
cli::cli_warn("Removed {sum(remove)} row{?s} containing missing values ({.fn geom_sf})")
179+
cli::cli_warn(paste0(
180+
"Removed {sum(remove)} row{?s} containing missing values or values ",
181+
"outside the scale range ({.fn geom_sf})."
182+
))
180183
}
181184
x <- x[!remove, , drop = FALSE]
182185
type_ind <- type_ind[!remove]

R/utilities.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ remove_missing <- function(df, na.rm = FALSE, vars = names(df), name = "",
9191
if (!na.rm) {
9292
if (name != "") name <- paste(" ({.fn ", name, "})", sep = "")
9393
msg <- paste0(
94-
"Removed {sum(missing)} rows containing ",
95-
if (finite) "non-finite" else "missing",
96-
" values", name, "."
94+
"Removed {sum(missing)} row{?s} containing ",
95+
if (finite) "non-finite" else "missing values or values",
96+
" outside the scale range", name, "."
9797
)
9898
cli::cli_warn(msg)
9999
}

tests/testthat/_snaps/geom-dotplot.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# NA's result in warning from stat_bindot
22

3-
Removed 2 rows containing missing values (`stat_bindot()`).
3+
Removed 2 rows containing missing values or values outside the scale range (`stat_bindot()`).
44

55
# weight aesthetic is checked
66

tests/testthat/_snaps/stat-boxplot.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# stat_boxplot drops missing rows with a warning
22

3-
Removed 10 rows containing missing values (`stat_boxplot()`).
3+
Removed 10 rows containing missing values or values outside the scale range (`stat_boxplot()`).
44

55
---
66

7-
Removed 10 rows containing missing values (`stat_boxplot()`).
7+
Removed 10 rows containing missing values or values outside the scale range (`stat_boxplot()`).
88

99
# stat_boxplot errors with missing x/y aesthetics
1010

tests/testthat/test-geom-bar.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ test_that("geom_bar removes bars with parts outside the plot limits", {
55

66
expect_warning( # warning created at render stage
77
ggplotGrob(p + ylim(0, 2.5)),
8-
"Removed 1 rows containing missing values"
8+
"Removed 1 row containing missing values or values outside the scale range"
99
)
1010
})
1111

tests/testthat/test-geom-col.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ test_that("geom_col removes columns with parts outside the plot limits", {
55

66
expect_warning( # warning created at render stage
77
ggplotGrob(p + ylim(0.5, 4)),
8-
"Removed 3 rows containing missing values"
8+
"Removed 3 rows containing missing values or values outside the scale range"
99
)
1010
expect_warning( # warning created at build stage
1111
ggplot_build(p + ylim(0, 2.5)),
12-
"Removed 1 rows containing missing values"
12+
"Removed 1 row containing missing values or values outside the scale range"
1313
)
1414
})
1515

tests/testthat/test-geom-path.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,6 @@ test_that("NA linetype is dropped with warning", {
9595
"NA linetype",
9696
ggplot(df, aes(x, y)) + geom_path(linetype = NA)
9797
),
98-
"containing missing values"
98+
"containing missing values or values outside the scale range"
9999
)
100100
})

tests/testthat/test-geom-sf.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,17 @@ test_that("geom_sf() removes rows containing missing aes", {
102102
p <- ggplot(pts)
103103
expect_warning(
104104
expect_identical(grob_xy_length(p + geom_sf(aes(size = size))), c(1L, 1L)),
105-
"Removed 1 row containing missing values"
105+
"Removed 1 row containing missing values or values outside the scale range"
106106
)
107107
expect_warning(
108108
expect_identical(grob_xy_length(p + geom_sf(aes(shape = shape))), c(1L, 1L)),
109-
"Removed 1 row containing missing values"
109+
"Removed 1 row containing missing values or values outside the scale range"
110110
)
111111
# default colour scale maps a colour even to a NA, so identity scale is needed to see if NA is removed
112112
expect_warning(
113113
expect_identical(grob_xy_length(p + geom_sf(aes(colour = colour)) + scale_colour_identity()),
114114
c(1L, 1L)),
115-
"Removed 1 row containing missing values"
115+
"Removed 1 row containing missing values or values outside the scale range"
116116
)
117117
})
118118

tests/testthat/test-scales.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ test_that("oob affects position values", {
112112
base + scale_y_continuous(limits = c(-0,5))
113113

114114
expect_warning(low_censor <- cdata(base + y_scale(c(0, 5), censor)),
115-
"Removed 1 rows containing missing values")
115+
"Removed 1 row containing missing values or values outside the scale range")
116116
expect_warning(mid_censor <- cdata(base + y_scale(c(3, 7), censor)),
117-
"Removed 2 rows containing missing values")
117+
"Removed 2 rows containing missing values or values outside the scale range")
118118

119119
low_squish <- cdata(base + y_scale(c(0, 5), squish))
120120
mid_squish <- cdata(base + y_scale(c(3, 7), squish))

0 commit comments

Comments
 (0)