Skip to content

Commit 6ba9275

Browse files
committed
Move warnings above layer()
And fix test of warning messages
1 parent b143ec6 commit 6ba9275

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

R/stat-function.r

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ stat_function <- function(mapping = NULL, data = NULL,
6464
na.rm = FALSE,
6565
show.legend = NA,
6666
inherit.aes = TRUE) {
67+
68+
# Warn if supplied mapping and/or data is going to be overwritten
69+
if (!is.null(mapping)) {
70+
warning("`mapping` is not used by stat_function()", call. = FALSE)
71+
}
72+
if (!is.null(data)) {
73+
warning("`data` is not used by stat_function()", call. = FALSE)
74+
}
75+
6776
layer(
6877
data = data,
6978
mapping = mapping,
@@ -81,15 +90,6 @@ stat_function <- function(mapping = NULL, data = NULL,
8190
...
8291
)
8392
)
84-
85-
# Warn if supplied mapping and/or data is going to be overwritten
86-
if (!is.null(mapping)) {
87-
warning("`mapping` is not used by stat_function()", call. = FALSE)
88-
}
89-
if (!is.null(data)) {
90-
warning("`data` is not used by stat_function()", call. = FALSE)
91-
}
92-
9393
}
9494

9595
#' @rdname ggplot2-ggproto

tests/testthat/test-stats-function.r

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ test_that("works with formula syntax", {
4949
})
5050

5151
test_that("`mapping` is not used by stat_function()", {
52-
expect_warning(stat_function(aes(), fun = identity), "Ignoring `mapping`")
52+
expect_warning(stat_function(aes(), fun = identity), "`mapping` is not used")
5353
})
5454

5555
test_that("`data` is not used by stat_function()", {
56-
expect_warning(stat_function(aes(), fun = identity), "Ignoring `data`")
56+
expect_warning(stat_function(data = mtcars, fun = identity), "`data` is not used")
5757
})

0 commit comments

Comments
 (0)