Here's one way of looking at proto objects. They are environments as I understand it, so using ls
gives you the names (apparently even for items extracted from the parent environment which is the plot object, p
.):
ls(p$layers[[1]])
# [1] "data" "geom" "geom_params" "inherit.aes" "mapping"
# [6] "position" "show_guide" "stat" "stat_params" "subset"
p$layers[[1]][["geom"]]
#geom_ribbon:
sapply( p$layers, "[[", "geom")
#---------------
[[1]]
geom_ribbon:
[[2]]
geom_line:
@Dason points out that you might have wanted a character vector as a result, so using sapply with "[[" again should satisfy that possible desire:
sapply( sapply( p$layers, "[[", "geom"), "[[", 'objname')
#[1] "ribbon" "line"
The changes in ggproto design consisted of making the names reside an extra layer deeper inside the class
-attributes:
lapply( sapply( p$layers, "[[", "geom"), function(x) attributes(x) )
#----------------
[[1]]
[[1]]$class
[1] "GeomRibbon" "Geom" "ggproto"
[[2]]
[[2]]$class
[1] "GeomLine" "GeomPath" "Geom" "ggproto"
sapply( sapply( p$layers, "[[", "geom"), function(x) class(x)[[1]][1] )
[1] "GeomRibbon" "GeomLine"