Skip to content

Commit d21f0c5

Browse files
committed
Revert ggplot() constructor to S3
1 parent d65cc75 commit d21f0c5

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

R/plot.R

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,19 @@
103103
#' mapping = aes(x = group, y = group_mean), data = group_means_df,
104104
#' colour = 'red', size = 3
105105
#' )
106-
ggplot <- S7::new_generic(
107-
"ggplot2", "data",
108-
fun = function(data, mapping = aes(), ..., environment = parent.frame()) {
109-
force(mapping)
110-
S7::S7_dispatch()
111-
}
112-
)
106+
ggplot <- function(
107+
data = NULL,
108+
mapping = aes(),
109+
...,
110+
environment = parent.frame()
111+
) {
112+
UseMethod("ggplot")
113+
}
114+
115+
#' @export
116+
ggplot.default <-
117+
function(data, mapping = aes(), ..., environment = parent.frame()) {
113118

114-
S7::method(ggplot, S7::class_any) <- function(
115-
data, mapping = aes(), ...,
116-
environment = parent.frame()) {
117119
if (!missing(mapping) && !is_mapping(mapping)) {
118120
cli::cli_abort(c(
119121
"{.arg mapping} must be created with {.fn aes}.",
@@ -137,13 +139,11 @@ S7::method(ggplot, S7::class_any) <- function(
137139
p
138140
}
139141

140-
S7::method(ggplot, S7::class_function) <-
141-
function(data, mapping = aes(), ...,
142-
environment = parent.frame()) {
142+
ggplot.function <- function(data, ...) {
143143
# Added to avoid functions end in ggplot.default
144144
cli::cli_abort(c(
145145
"{.arg data} cannot be a function.",
146-
"i" = "Have you misspelled the {.arg data} argument in {.fn ggplot}"
146+
"i" = "Have you misspelled the {.arg data} argument in {.fn ggplot}?"
147147
))
148148
}
149149

0 commit comments

Comments
 (0)