Skip to content

Commit c7aa7fd

Browse files
committed
include example of checks argument
1 parent 295e36c commit c7aa7fd

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

R/make-constructor.R

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,21 @@ NULL
4141
#' p <- ggplot(mtcars, aes(disp, mpg))
4242
#' p + geom_test()
4343
#' p + geom_test(grob = grid::circleGrob())
44+
#'
45+
#' # The `checks` argument can be used to evaluate arbitrary expressions in
46+
#' # the constructor before building the layer.
47+
#' geom_path2 <- make_constructor(
48+
#' GeomPath, checks = rlang::exprs(
49+
#' match.arg(lineend, c("butt", "round", "square")),
50+
#' match.arg(linejoin, c("round", "mitre", "bevel"))
51+
#' )
52+
#' )
53+
#'
54+
#' # Note the inclusion of the expressions
55+
#' print(geom_path2)
56+
#'
57+
#' # Argument mismatch is detected
58+
#' try(geom_path2(linejoin = "foo"))
4459
make_constructor <- function(x, ...) {
4560
UseMethod("make_constructor")
4661
}

man/make_constructor.Rd

Lines changed: 15 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)