Skip to content

Commit fb73191

Browse files
authored
Improved error messages for plot addition. (#3600)
* improved error messages for plot addition. * Use same language for theme addition errors.
1 parent 6efb0d3 commit fb73191

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

R/plot-construction.r

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ ggplot_add <- function(object, plot, object_name) {
8888
}
8989
#' @export
9090
ggplot_add.default <- function(object, plot, object_name) {
91-
stop("Don't know how to add ", object_name, " to a plot", call. = FALSE)
91+
stop("Can't add `", object_name, "` to a ggplot object.", call. = FALSE)
9292
}
9393
#' @export
9494
ggplot_add.NULL <- function(object, plot, object_name) {
@@ -102,8 +102,9 @@ ggplot_add.data.frame <- function(object, plot, object_name) {
102102
#' @export
103103
ggplot_add.function <- function(object, plot, object_name) {
104104
stop(
105-
"Don't know how to add ", object_name, " to a plot. Did you mean ",
106-
object_name, "()?", call. = FALSE
105+
"Can't add `", object_name, "` to a ggplot object.\n",
106+
"Did you forget to add parentheses, as in `",
107+
object_name, "()`?", call. = FALSE
107108
)
108109
}
109110
#' @export

R/theme.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ plot_theme <- function(x, default = theme_get()) {
436436
#' @keywords internal
437437
add_theme <- function(t1, t2, t2name) {
438438
if (!is.theme(t2)) {
439-
stop("Don't know how to add ", t2name, " to a theme object",
439+
stop("Can't add `", t2name, "` to a theme object.",
440440
call. = FALSE)
441441
}
442442

0 commit comments

Comments
 (0)