diff --git a/R/stat-boxplot.r b/R/stat-boxplot.r index ac8ab5dc27..e9833d1720 100644 --- a/R/stat-boxplot.r +++ b/R/stat-boxplot.r @@ -51,7 +51,7 @@ StatBoxplot <- ggproto("StatBoxplot", Stat, data$x <- data$x %||% 0 data <- remove_missing( data, - na.rm = FALSE, + na.rm = params$na.rm, vars = "x", name = "stat_boxplot" ) diff --git a/tests/testthat/test-stat-boxplot.R b/tests/testthat/test-stat-boxplot.R index 8d6baacded..7887ad7145 100644 --- a/tests/testthat/test-stat-boxplot.R +++ b/tests/testthat/test-stat-boxplot.R @@ -19,3 +19,11 @@ test_that("stat_boxplot drops missing rows with a warning", { "Removed 10 rows containing missing values \\(stat_boxplot\\)\\." ) }) + +test_that("stat_boxplot can suppress warning about missing rows", { + p1 <- ggplot(PlantGrowth, aes(x = group, y = weight)) + + geom_boxplot(position = "dodge", na.rm = TRUE) + + scale_x_discrete(limits = c("trt1", "ctrl")) + + expect_silent(ggplot_build(p1)) +})