Skip to content

Commit b73265b

Browse files
committed
Add layer_data method to Layer to get the data from the layer or resolve it if its a waiver or function
1 parent d3cf225 commit b73265b

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

R/layer.r

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,19 @@ Layer <- ggproto("Layer", NULL,
101101
cat(snakeize(class(self$position)[[1]]), "\n")
102102
},
103103

104+
layer_data = function(self, plot_data) {
105+
if (is.waive(self$data)) {
106+
return(plot_data)
107+
} else if (is.function(self$data)) {
108+
data <- self$data(plot_data)
109+
if (!is.data.frame(data)) {
110+
stop("Data function must return a data.frame")
111+
}
112+
return(data)
113+
}
114+
self$data
115+
},
116+
104117
compute_aesthetics = function(self, data, plot) {
105118
# For annotation geoms, it is useful to be able to ignore the default aes
106119
if (self$inherit.aes) {

0 commit comments

Comments
 (0)