Skip to content

Commit

Permalink
Add plot.R6 method, which calls $plot on object. Closes #77
Browse files Browse the repository at this point in the history
  • Loading branch information
wch committed Jan 25, 2016
1 parent fb4503e commit f87fe29
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ License: MIT + file LICENSE
URL: https://github.com/wch/R6/
LazyData: true
VignetteBuilder: knitr
RoxygenNote: 5.0.1
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Generated by roxygen2 (4.1.1): do not edit by hand
# Generated by roxygen2: do not edit by hand

S3method(format,R6)
S3method(format,R6ClassGenerator)
S3method(plot,R6)
S3method(print,R6)
S3method(print,R6ClassGenerator)
export(R6Class)
6 changes: 6 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
R6 2.1.2.9000
-------------------------------------------------------------------------------

* The `plot` S3 method for R6 objects will call `$plot` on the object if
present. (#77)

R6 2.1.2
-------------------------------------------------------------------------------

Expand Down
10 changes: 10 additions & 0 deletions R/print.R
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,13 @@ trim <- function(str, n = 60) {
if (nchar(str) > n) paste(substr(str, 1, 56), "...")
else str
}


#' @export
plot.R6 <- function(x, ...) {
if (is.function(x$plot)) {
x$plot(...)
} else {
stop(paste0("No plot method defined for R6 class ", class(x)[1]))
}
}
2 changes: 1 addition & 1 deletion man/R6Class.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f87fe29

Please sign in to comment.