Skip to content

Commit fa9f6d2

Browse files
committed
document
1 parent 8c8f795 commit fa9f6d2

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

R/boilerplates.R

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,39 @@
22
#' @include scale-type.R
33
NULL
44

5+
#' Produce boilerplate constructors
6+
#'
7+
#' The `boilerplate()` functions sets up a user-facing constructor for ggproto
8+
#' classes. Currently, `boilerplate()` is implemented for `Geom` classes.
9+
#'
10+
#' @param x An object to setup a constructor for.
11+
#' @param ... Name-value pairs to use as additional arguments in the
12+
#' constructor. For layers, these are passed on to [`layer(params)`][layer()].
13+
#' @param checks Expressions evaluated before construction of the object.
14+
#' Can be a `{}` block to include multiple expressions.
15+
#'
16+
#' @return A function
517
#' @export
18+
#'
19+
#' @examples
20+
#' # For testing purposes, a geom that returns grobs
21+
#' GeomTest <- ggproto(
22+
#' "GeomTest", Geom,
23+
#' draw_group = function(..., grob = grid::pointsGrob()) {
24+
#' return(grob)
25+
#' }
26+
#' )
27+
#' # Creating a constructor
28+
#' geom_test <- boilerplate(GeomTest)
29+
#'
30+
#' # Note that `grob` is automatically an argument to the function
31+
#' names(formals(geom_test))
32+
#'
33+
#' # Use in a plot
34+
#' set.seed(1234)
35+
#' p <- ggplot(mtcars, aes(disp, mpg))
36+
#' p + geom_test()
37+
#' p + geom_test(grob = grid::circleGrob())
638
boilerplate <- function(x, ...) {
739
UseMethod("boilerplate")
840
}

man/boilerplate.Rd

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

0 commit comments

Comments
 (0)