Skip to content

Commit ab91c1e

Browse files
committed
included custom warning messages if data and/or mapping is supplied
1 parent ed978ab commit ab91c1e

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

R/stat-function.r

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,12 @@ stat_function <- function(mapping = NULL, data = NULL,
8484

8585
# Warn if supplied mapping and/or data is going to be overwritten
8686
if (!is.null(mapping)) {
87-
warn_overwritten_args("stat_function()", "mapping", "group")
87+
warning("`mapping` is not used by stat_function()", call. = FALSE)
8888
}
8989
if (!is.null(data)) {
90-
warn_overwritten_args("stat_function()", "data", "group")
90+
warning("`data` is not used by stat_function()", call. = FALSE)
9191
}
9292

93-
9493
}
9594

9695
#' @rdname ggplot2-ggproto

tests/testthat/test-stats-function.r

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,15 @@ test_that("works with formula syntax", {
4747
expect_equal(ret$x, s)
4848
expect_equal(ret$y, s^2)
4949
})
50+
51+
test_that("can control whether to preserve total or individual width", {
52+
df <- data_frame(x = c("a", "b", "b"), y = c("a", "a", "b"))
53+
54+
p_total <- ggplot(df, aes(x, fill = y)) +
55+
geom_bar(position = position_dodge(preserve = "total"), width = 1)
56+
p_single <- ggplot(df, aes(x, fill = y)) +
57+
geom_bar(position = position_dodge(preserve = "single"), width = 1)
58+
59+
expect_equal(layer_data(p_total)$x, c(1, 2.25, 1.75))
60+
expect_equal(layer_data(p_single)$x, c(0.75, 2.25, 1.75))
61+
})

0 commit comments

Comments
 (0)