Skip to content

Commit 26f9f8f

Browse files
committed
automatically fill in parameters
1 parent 3eee99f commit 26f9f8f

31 files changed

+112
-147
lines changed

R/boilerplates.R

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,31 @@ boilerplate.Geom <- function(x, ..., env = caller_env()) {
2323
cli::cli_abort("{.arg geom} is a reserved argument.")
2424
}
2525

26+
# Fill in values for parameters from draw functions
27+
known_params <-
28+
unique(c(names(args), fixed_fmls_names, "flipped_aes", x$aesthetics()))
29+
missing_params <- setdiff(x$parameters(), known_params)
30+
if (length(missing_params) > 0) {
31+
draw_args <- ggproto_formals(x$draw_panel)
32+
if ("..." %in% names(draw_args)) {
33+
draw_args <- ggproto_formals(x$draw_group)
34+
}
35+
params <- intersect(missing_params, names(draw_args))
36+
extra_args <- c(extra_args, params)
37+
for (param in params) {
38+
if (!identical(draw_args[[param]], quote(expr = ))) {
39+
args[param] <- draw_args[param]
40+
}
41+
}
42+
missing_params <- setdiff(missing_params, names(args))
43+
if (length(missing_params) > 0) {
44+
cli::cli_warn(
45+
"In {.fn geom_{geom}}: please consider providing default values for: \\
46+
{missing_params}."
47+
)
48+
}
49+
}
50+
2651
# Build function formals
2752
fmls <- list2(
2853
mapping = args$mapping,

R/geom-bar.R

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,4 @@ GeomBar <- ggproto("GeomBar", GeomRect,
136136
#' ggplot(df, aes(x, y)) + geom_col(just = 0.5)
137137
#' # Columns begin on the first day of the month
138138
#' ggplot(df, aes(x, y)) + geom_col(just = 1)
139-
geom_bar <- boilerplate(
140-
GeomBar, stat = "count", position = "stack",
141-
just = 0.5, orientation = NA,
142-
lineend = "butt", linejoin = "mitre"
143-
)
139+
geom_bar <- boilerplate(GeomBar, stat = "count", position = "stack", just = 0.5)

R/geom-bin2d.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ NULL
3131
#'
3232
#' # Or by specifying the width of the bins
3333
#' d + geom_bin_2d(binwidth = c(0.1, 0.1))
34-
geom_bin_2d <- boilerplate(
35-
GeomTile, stat = "bin2d",
36-
lineend = "butt", linejoin = "mitre"
37-
)
34+
geom_bin_2d <- boilerplate(GeomTile, stat = "bin2d")
3835

3936
#' @export
4037
#' @rdname geom_bin_2d

R/geom-col.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#' @export
22
#' @rdname geom_bar
3-
geom_col <- boilerplate(
4-
GeomBar, position = "stack",
5-
just = 0.5, lineend = "butt", linejoin = "mitre"
6-
)
3+
geom_col <- boilerplate(GeomBar, position = "stack", just = 0.5)
74

85
#' @rdname ggplot2-ggproto
96
#' @format NULL

R/geom-contour.R

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,14 @@ GeomContourFilled <- ggproto("GeomContourFilled", GeomPolygon)
8585
#' }
8686
geom_contour <- boilerplate(
8787
GeomContour, stat = "contour",
88-
bins = NULL, binwidth = NULL, breaks = NULL,
89-
lineend = "butt", linejoin = "round", linemitre = 10,
90-
arrow = NULL, arrow.fill = NULL
88+
# Passed to contour stat:
89+
bins = NULL, binwidth = NULL, breaks = NULL
9190
)
9291

9392
#' @rdname geom_contour
9493
#' @export
9594
geom_contour_filled <- boilerplate(
9695
GeomContourFilled, stat = "contour_filled",
97-
bins = NULL, binwidth = NULL, breaks = NULL,
98-
rule = "evenodd",
99-
lineend = "butt", linejoin = "round", linemitre = 10
96+
# Passed to contour_filled stat:
97+
bins = NULL, binwidth = NULL, breaks = NULL
10098
)

R/geom-crossbar.R

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,4 @@ GeomCrossbar <- ggproto("GeomCrossbar", Geom,
9393

9494
#' @export
9595
#' @rdname geom_linerange
96-
geom_crossbar <- boilerplate(
97-
GeomCrossbar,
98-
fatten = 2.5, orientation = NA, width = NULL,
99-
lineend = "butt", linejoin = "mitre"
100-
)
96+
geom_crossbar <- boilerplate(GeomCrossbar)

R/geom-curve.R

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,4 @@ GeomCurve <- ggproto("GeomCurve", GeomSegment,
4747
#' @inheritParams grid::curveGrob
4848
#' @export
4949
#' @rdname geom_segment
50-
geom_curve <- boilerplate(
51-
GeomCurve,
52-
curvature = 0.5, angle = 90, ncp = 5,
53-
arrow = NULL, arrow.fill = NULL,
54-
lineend = "butt"
55-
)
50+
geom_curve <- boilerplate(GeomCurve)

R/geom-errorbar.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,4 @@ GeomErrorbar <- ggproto("GeomErrorbar", Geom,
5858

5959
#' @export
6060
#' @rdname geom_linerange
61-
geom_errorbar <- boilerplate(
62-
GeomErrorbar,
63-
orientation = NA, lineend = "butt"
64-
)
61+
geom_errorbar <- boilerplate(GeomErrorbar, orientation = NA)

R/geom-errorbarh.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@ GeomErrorbarh <- ggproto("GeomErrorbarh", Geom,
6969
#' p +
7070
#' geom_point() +
7171
#' geom_errorbarh(aes(xmax = resp + se, xmin = resp - se, height = .2))
72-
geom_errorbarh <- boilerplate(GeomErrorbarh, lineend = "butt")
72+
geom_errorbarh <- boilerplate(GeomErrorbarh)

R/geom-hex.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,4 @@ GeomHex <- ggproto("GeomHex", Geom,
100100
#' d + geom_hex(binwidth = c(1, 1000))
101101
#' d + geom_hex(binwidth = c(.1, 500))
102102
#' }
103-
geom_hex <- boilerplate(
104-
GeomHex, stat = 'binhex',
105-
lineend = "butt", linejoin = "mitre", linemitre = 10
106-
)
103+
geom_hex <- boilerplate(GeomHex, stat = 'binhex')

0 commit comments

Comments
 (0)