Skip to content

Commit f5c40d0

Browse files
committed
move by_layer
1 parent 81070f8 commit f5c40d0

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

R/plot-build.R

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,23 @@ get_layer_grob <- function(plot = get_last_plot(), i = 1L) {
177177
#' @export
178178
#' @rdname ggplot_build
179179
layer_grob <- get_layer_grob
180+
181+
# Apply function to layer and matching data
182+
by_layer <- function(f, layers, data, step = NULL) {
183+
ordinal <- label_ordinal()
184+
out <- vector("list", length(data))
185+
try_fetch(
186+
for (i in seq_along(data)) {
187+
out[[i]] <- f(l = layers[[i]], d = data[[i]])
188+
},
189+
error = function(cnd) {
190+
cli::cli_abort(c(
191+
"Problem while {step}.",
192+
"i" = "Error occurred in the {ordinal(i)} layer."),
193+
call = layers[[i]]$constructor,
194+
parent = cnd
195+
)
196+
}
197+
)
198+
out
199+
}

R/plot-render.R

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,26 +64,6 @@ ggplotGrob <- function(x) {
6464
S7::method(as.gtable, class_ggplot) <- function(x, ...) ggplotGrob(x)
6565
S7::method(as.gtable, class_ggplot_built) <- function(x, ...) ggplot_gtable(x)
6666

67-
# Apply function to layer and matching data
68-
by_layer <- function(f, layers, data, step = NULL) {
69-
ordinal <- label_ordinal()
70-
out <- vector("list", length(data))
71-
try_fetch(
72-
for (i in seq_along(data)) {
73-
out[[i]] <- f(l = layers[[i]], d = data[[i]])
74-
},
75-
error = function(cnd) {
76-
cli::cli_abort(c(
77-
"Problem while {step}.",
78-
"i" = "Error occurred in the {ordinal(i)} layer."),
79-
call = layers[[i]]$constructor,
80-
parent = cnd
81-
)
82-
}
83-
)
84-
out
85-
}
86-
8767
# Add the legends to the gtable
8868
table_add_legends <- function(table, legends, theme) {
8969

0 commit comments

Comments
 (0)