-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed
Description
This is a classic srcref
problem affecting readability when printing $constructor
to console
library(ggplot2)
p_expr <- parse(text = "
p <- ggplot() +
geom_point(size = 5)
")
eval(p_expr)
# Whole plot code displayed on print
p$layers[[1]]$constructor
#> p <- ggplot() +
#> geom_point(size = 5)
# Stripping srcref shows the actual layer code
attr(p$layers[[1]]$constructor, "srcref") <- NULL
p$layers[[1]]$constructor
#> geom_point(size = 5)
A simple fix would be to apply this one-liner where the constructor property is resolved in layer()
:
Line 183 in 7fb5760
fr_call <- layer_class$constructor %||% frame_call(call_env) %||% current_call() |
Stripping the srcref of fr_call
above would naturally resolve one other case where this happens (in layer_sf()
, since it gets forwarded to layer()
)
Lines 25 to 28 in 7fb5760
layer_class <- ggproto(NULL, LayerSf, | |
constructor = frame_call(call_env), | |
legend_key_type = legend_key_type | |
) |
If that seems reasonable, I can file a PR! :)
Metadata
Metadata
Assignees
Labels
No labels