Skip to content

Commit e14be3c

Browse files
committed
repair invalid theme
1 parent 3ae8031 commit e14be3c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

R/plot-construction.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,20 @@ update_ggplot <- S7::new_generic("update_ggplot", c("object", "plot"))
134134

135135
S7::method(update_ggplot, list(S7::class_any, class_ggplot)) <-
136136
function(object, plot, object_name, ...) {
137+
138+
if (!S7::S7_inherits(object) && inherits(object, "theme")) {
139+
# For backward compatibility, we try to cast old S3 themes (lists with
140+
# the class 'theme') to proper themes. People *should* use `theme()`,
141+
# so we should be pushy here.
142+
# TODO: Promote warning to error in future release.
143+
cli::cli_warn(c(
144+
"{object_name} is not a valid theme.",
145+
"Please use {.fn theme} to construct themes."
146+
))
147+
object <- theme(!!!object)
148+
return(update_ggplot(object, plot))
149+
}
150+
137151
cli::cli_abort("Can't add {.var {object_name}} to a {.cls ggplot} object.")
138152
}
139153

0 commit comments

Comments
 (0)