Skip to content

Commit 0310be8

Browse files
committed
Write methods for external generics as S7
1 parent 90d644f commit 0310be8

File tree

7 files changed

+15
-26
lines changed

7 files changed

+15
-26
lines changed

NAMESPACE

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ S3method(ggplot_build,ggplot)
5858
S3method(ggplot_build,ggplot_built)
5959
S3method(ggplot_gtable,ggplot_built)
6060
S3method(grid.draw,absoluteGrob)
61-
S3method(grid.draw,ggplot)
6261
S3method(grobHeight,absoluteGrob)
6362
S3method(grobHeight,zeroGrob)
6463
S3method(grobWidth,absoluteGrob)
@@ -87,19 +86,16 @@ S3method(pattern_alpha,GridPattern)
8786
S3method(pattern_alpha,GridTilingPattern)
8887
S3method(pattern_alpha,default)
8988
S3method(pattern_alpha,list)
90-
S3method(plot,ggplot)
9189
S3method(predictdf,default)
9290
S3method(predictdf,glm)
9391
S3method(predictdf,locfit)
9492
S3method(predictdf,loess)
9593
S3method(print,"ggplot2::mapping")
9694
S3method(print,element)
97-
S3method(print,ggplot)
9895
S3method(print,ggplot2_bins)
9996
S3method(print,ggproto)
10097
S3method(print,ggproto_method)
10198
S3method(print,rel)
102-
S3method(print,theme)
10399
S3method(scale_type,Date)
104100
S3method(scale_type,POSIXt)
105101
S3method(scale_type,character)
@@ -113,7 +109,6 @@ S3method(scale_type,logical)
113109
S3method(scale_type,numeric)
114110
S3method(scale_type,ordered)
115111
S3method(scale_type,sfc)
116-
S3method(summary,ggplot)
117112
S3method(vec_cast,character.mapped_discrete)
118113
S3method(vec_cast,double.mapped_discrete)
119114
S3method(vec_cast,factor.mapped_discrete)

R/plot.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,10 @@ plot_clone <- function(plot) {
194194
#' @param ... other arguments not used by this method
195195
#' @keywords hplot
196196
#' @return Invisibly returns the original plot.
197-
#' @export
198-
#' @method print ggplot
197+
#' @name print.ggplot
198+
#' @usage
199+
#' print(x, newpage = is.null(vp), vp = NULL, ...)
200+
#' plot(x, newpage = is.null(vp), vp = NULL, ...)
199201
#' @examples
200202
#' colours <- list(~class, ~drv, ~fl)
201203
#'
@@ -210,7 +212,9 @@ plot_clone <- function(plot) {
210212
#' print(ggplot(mpg, aes_(~ displ, ~ hwy, colour = colour)) +
211213
#' geom_point())
212214
#' }
213-
print.ggplot <- function(x, newpage = is.null(vp), vp = NULL, ...) {
215+
S7::method(print, class_ggplot) <-
216+
S7::method(plot, class_ggplot) <-
217+
function(x, newpage = is.null(vp), vp = NULL, ...) {
214218
set_last_plot(x)
215219
if (newpage) grid.newpage()
216220

@@ -239,7 +243,3 @@ print.ggplot <- function(x, newpage = is.null(vp), vp = NULL, ...) {
239243

240244
invisible(x)
241245
}
242-
#' @rdname print.ggplot
243-
#' @method plot ggplot
244-
#' @export
245-
plot.ggplot <- print.ggplot

R/save.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,7 @@ validate_device <- function(device, filename = NULL, dpi = 300, call = caller_en
313313
dev
314314
}
315315

316-
#' @export
317-
grid.draw.ggplot <- function(x, recording = TRUE) {
318-
print(x)
319-
}
316+
S7::method(grid.draw, class_ggplot) <- function(x, recording = TRUE) print(x)
320317

321318
absorb_grdevice_args <- function(f) {
322319
function(..., type, antialias) {

R/summary.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
#' @param object ggplot2 object to summarise
44
#' @param ... other arguments ignored (for compatibility with generic)
55
#' @keywords internal
6-
#' @method summary ggplot
7-
#' @export
6+
#' @name summary.ggplot
7+
#' @usage summary(object, ...)
88
#' @examples
99
#' p <- ggplot(mtcars, aes(mpg, wt)) +
1010
#' geom_point()
1111
#' summary(p)
12-
summary.ggplot <- function(object, ...) {
12+
S7::method(summary, class_ggplot) <- function(object, ...) {
1313
wrap <- function(x) paste(
1414
paste(strwrap(x, exdent = 2), collapse = "\n"),
1515
"\n", sep = ""

R/theme.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -959,5 +959,4 @@ combine_elements <- function(e1, e2) {
959959
.subset2(x, ...)
960960
}
961961

962-
#' @export
963-
print.theme <- function(x, ...) utils::str(x)
962+
S7::method(print, theme) <- function(x, ...) utils::str(x)

man/print.ggplot.Rd

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/summary.ggplot.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)