Skip to content

Commit 5188f5e

Browse files
authored
better error message when trying to add a function to a plot. Closes #3571. (#3594)
1 parent a1143e1 commit 5188f5e

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ S3method(fortify,tbl_df)
4545
S3method(ggplot,"function")
4646
S3method(ggplot,default)
4747
S3method(ggplot_add,"NULL")
48+
S3method(ggplot_add,"function")
4849
S3method(ggplot_add,Coord)
4950
S3method(ggplot_add,Facet)
5051
S3method(ggplot_add,Layer)

R/plot-construction.r

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ ggplot_add.data.frame <- function(object, plot, object_name) {
100100
plot
101101
}
102102
#' @export
103+
ggplot_add.function <- function(object, plot, object_name) {
104+
stop(
105+
"Don't know how to add ", object_name, " to a plot. Did you mean ",
106+
object_name, "()?", call. = FALSE
107+
)
108+
}
109+
#' @export
103110
ggplot_add.theme <- function(object, plot, object_name) {
104111
plot$theme <- add_theme(plot$theme, object)
105112
plot

0 commit comments

Comments
 (0)