Possibly inconsistent treatment of extractor in `purr::map()`

Just saw this excellent gist and noticed that the author used lapply() rather than map(). When reproducing their example, I ran it using map() and observed that the results are not quite the same. I can reproduce their results if I explicitly use the extractor function [[.

Author's original code assigns to aes_list(). My first attempt is aes_list2(). Replica of their result is found in aes_list3().

Note that the elements of the geoms object are environments, not lists. I suspect this may have something to do with what I'm observing.

library(tidyverse)

geom_names <- apropos("^Geom", ignore.case = FALSE)
geoms <- mget(geom_names, env = asNamespace("ggplot2"))
aes_list <- lapply(geoms, function(x) x$default_aes)
aes_list2 <- map(geoms, 'default_aes')
aes_list3 <- map(geoms, `[[`, 'default_aes')

all.equal(aes_list, aes_list2)
all.equal(aes_list, aes_list3)

I'm not 100% clear as to the cause (might be worth filing an issue in the purrr repo on this), but just to elucidate a bit more here's a reprex with output…

library(tidyverse)

geom_names <- apropos("^Geom", ignore.case = FALSE)
geoms <- mget(geom_names, env = asNamespace("ggplot2"))
aes_list <- lapply(geoms, function(x) x$default_aes)
aes_list2 <- map(geoms, 'default_aes')
aes_list3 <- map(geoms, `[[`, 'default_aes')

all.equal(aes_list, aes_list2)
#>  [1] "Component \"Geom\": Modes: list, NULL"                                                
#>  [2] "Component \"Geom\": Attributes: < Modes: list, NULL >"                                
#>  [3] "Component \"Geom\": Attributes: < Lengths: 2, 0 >"                                    
#>  [4] "Component \"Geom\": Attributes: < names for target but not for current >"             
#>  [5] "Component \"Geom\": Attributes: < current is not list-like >"                         
#>  [6] "Component \"Geom\": current is not list-like"                                         
#>  [7] "Component \"GeomAnnotationMap\": Modes: list, NULL"                                   
#>  [8] "Component \"GeomAnnotationMap\": Lengths: 6, 0"                                       
#>  [9] "Component \"GeomAnnotationMap\": names for target but not for current"                
#> [10] "Component \"GeomAnnotationMap\": Attributes: < Modes: list, NULL >"                   
#> [11] "Component \"GeomAnnotationMap\": Attributes: < Lengths: 1, 0 >"                       
#> [12] "Component \"GeomAnnotationMap\": Attributes: < names for target but not for current >"
#> [13] "Component \"GeomAnnotationMap\": Attributes: < current is not list-like >"            
#> [14] "Component \"GeomAnnotationMap\": current is not list-like"                            
#> [15] "Component \"GeomBar\": Modes: list, NULL"                                             
#> [16] "Component \"GeomBar\": Lengths: 5, 0"                                                 
#> [17] "Component \"GeomBar\": names for target but not for current"                          
#> [18] "Component \"GeomBar\": Attributes: < Modes: list, NULL >"                             
#> [19] "Component \"GeomBar\": Attributes: < Lengths: 1, 0 >"                                 
#> [20] "Component \"GeomBar\": Attributes: < names for target but not for current >"          
#> [21] "Component \"GeomBar\": Attributes: < current is not list-like >"                      
#> [22] "Component \"GeomBar\": current is not list-like"                                      
#> [23] "Component \"GeomBlank\": Modes: list, NULL"                                           
#> [24] "Component \"GeomBlank\": Attributes: < Modes: list, NULL >"                           
#> [25] "Component \"GeomBlank\": Attributes: < Lengths: 2, 0 >"                               
#> [26] "Component \"GeomBlank\": Attributes: < names for target but not for current >"        
#> [27] "Component \"GeomBlank\": Attributes: < current is not list-like >"                    
#> [28] "Component \"GeomBlank\": current is not list-like"                                    
#> [29] "Component \"GeomCol\": Modes: list, NULL"                                             
#> [30] "Component \"GeomCol\": Lengths: 5, 0"                                                 
#> [31] "Component \"GeomCol\": names for target but not for current"                          
#> [32] "Component \"GeomCol\": Attributes: < Modes: list, NULL >"                             
#> [33] "Component \"GeomCol\": Attributes: < Lengths: 1, 0 >"                                 
#> [34] "Component \"GeomCol\": Attributes: < names for target but not for current >"          
#> [35] "Component \"GeomCol\": Attributes: < current is not list-like >"                      
#> [36] "Component \"GeomCol\": current is not list-like"                                      
#> [37] "Component \"GeomLine\": Modes: list, NULL"                                            
#> [38] "Component \"GeomLine\": Lengths: 4, 0"                                                
#> [39] "Component \"GeomLine\": names for target but not for current"                         
#> [40] "Component \"GeomLine\": Attributes: < Modes: list, NULL >"                            
#> [41] "Component \"GeomLine\": Attributes: < Lengths: 1, 0 >"                                
#> [42] "Component \"GeomLine\": Attributes: < names for target but not for current >"         
#> [43] "Component \"GeomLine\": Attributes: < current is not list-like >"                     
#> [44] "Component \"GeomLine\": current is not list-like"                                     
#> [45] "Component \"GeomMap\": Modes: list, NULL"                                             
#> [46] "Component \"GeomMap\": Lengths: 6, 0"                                                 
#> [47] "Component \"GeomMap\": names for target but not for current"                          
#> [48] "Component \"GeomMap\": Attributes: < Modes: list, NULL >"                             
#> [49] "Component \"GeomMap\": Attributes: < Lengths: 1, 0 >"                                 
#> [50] "Component \"GeomMap\": Attributes: < names for target but not for current >"          
#> [51] "Component \"GeomMap\": Attributes: < current is not list-like >"                      
#> [52] "Component \"GeomMap\": current is not list-like"                                      
#> [53] "Component \"GeomRasterAnn\": Modes: list, NULL"                                       
#> [54] "Component \"GeomRasterAnn\": Attributes: < Modes: list, NULL >"                       
#> [55] "Component \"GeomRasterAnn\": Attributes: < Lengths: 2, 0 >"                           
#> [56] "Component \"GeomRasterAnn\": Attributes: < names for target but not for current >"    
#> [57] "Component \"GeomRasterAnn\": Attributes: < current is not list-like >"                
#> [58] "Component \"GeomRasterAnn\": current is not list-like"                                
#> [59] "Component \"GeomSpoke\": Modes: list, NULL"                                           
#> [60] "Component \"GeomSpoke\": Lengths: 4, 0"                                               
#> [61] "Component \"GeomSpoke\": names for target but not for current"                        
#> [62] "Component \"GeomSpoke\": Attributes: < Modes: list, NULL >"                           
#> [63] "Component \"GeomSpoke\": Attributes: < Lengths: 1, 0 >"                               
#> [64] "Component \"GeomSpoke\": Attributes: < names for target but not for current >"        
#> [65] "Component \"GeomSpoke\": Attributes: < current is not list-like >"                    
#> [66] "Component \"GeomSpoke\": current is not list-like"                                    
#> [67] "Component \"GeomStep\": Modes: list, NULL"                                            
#> [68] "Component \"GeomStep\": Lengths: 4, 0"                                                
#> [69] "Component \"GeomStep\": names for target but not for current"                         
#> [70] "Component \"GeomStep\": Attributes: < Modes: list, NULL >"                            
#> [71] "Component \"GeomStep\": Attributes: < Lengths: 1, 0 >"                                
#> [72] "Component \"GeomStep\": Attributes: < names for target but not for current >"         
#> [73] "Component \"GeomStep\": Attributes: < current is not list-like >"                     
#> [74] "Component \"GeomStep\": current is not list-like"
all.equal(aes_list, aes_list3)
#> [1] TRUE

str(aes_list)
#> List of 43
#>  $ Geom             : Named list()
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomAbline       :List of 4
#>   ..$ colour  : chr "black"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomAnnotationMap:List of 6
#>   ..$ colour  : chr "NA"
#>   ..$ fill    : chr "grey20"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..$ subgroup: NULL
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomArea         :List of 5
#>   ..$ colour  : logi NA
#>   ..$ fill    : chr "grey20"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomBar          :List of 5
#>   ..$ colour  : logi NA
#>   ..$ fill    : chr "grey35"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomBlank        : Named list()
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomBoxplot      :List of 7
#>   ..$ weight  : num 1
#>   ..$ colour  : chr "grey20"
#>   ..$ fill    : chr "white"
#>   ..$ size    : num 0.5
#>   ..$ alpha   : logi NA
#>   ..$ shape   : num 19
#>   ..$ linetype: chr "solid"
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomCol          :List of 5
#>   ..$ colour  : logi NA
#>   ..$ fill    : chr "grey35"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomContour      :List of 5
#>   ..$ weight  : num 1
#>   ..$ colour  : chr "#3366FF"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomCrossbar     :List of 5
#>   ..$ colour  : chr "black"
#>   ..$ fill    : logi NA
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomCurve        :List of 4
#>   ..$ colour  : chr "black"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomCustomAnn    :List of 4
#>   ..$ xmin: num -Inf
#>   ..$ xmax: num Inf
#>   ..$ ymin: num -Inf
#>   ..$ ymax: num Inf
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomDensity      :List of 6
#>   ..$ fill    : logi NA
#>   ..$ weight  : num 1
#>   ..$ colour  : chr "black"
#>   ..$ alpha   : logi NA
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>  $ GeomDensity2d    :List of 4
#>   ..$ colour  : chr "#3366FF"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomDotplot      :List of 5
#>   ..$ colour  : chr "black"
#>   ..$ fill    : chr "black"
#>   ..$ alpha   : logi NA
#>   ..$ stroke  : num 1
#>   ..$ linetype: chr "solid"
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomErrorbar     :List of 5
#>   ..$ colour  : chr "black"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ width   : num 0.5
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomErrorbarh    :List of 5
#>   ..$ colour  : chr "black"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ height  : num 0.5
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomHex          :List of 5
#>   ..$ colour  : logi NA
#>   ..$ fill    : chr "grey50"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomHline        :List of 4
#>   ..$ colour  : chr "black"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomLabel        :List of 10
#>   ..$ colour    : chr "black"
#>   ..$ fill      : chr "white"
#>   ..$ size      : num 3.88
#>   ..$ angle     : num 0
#>   ..$ hjust     : num 0.5
#>   ..$ vjust     : num 0.5
#>   ..$ alpha     : logi NA
#>   ..$ family    : chr ""
#>   ..$ fontface  : num 1
#>   ..$ lineheight: num 1.2
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomLine         :List of 4
#>   ..$ colour  : chr "black"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomLinerange    :List of 4
#>   ..$ colour  : chr "black"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomLogticks     :List of 4
#>   ..$ colour  : chr "black"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : num 1
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomMap          :List of 6
#>   ..$ colour  : chr "NA"
#>   ..$ fill    : chr "grey20"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..$ subgroup: NULL
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomPath         :List of 4
#>   ..$ colour  : chr "black"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomPoint        :List of 6
#>   ..$ shape : num 19
#>   ..$ colour: chr "black"
#>   ..$ size  : num 1.5
#>   ..$ fill  : logi NA
#>   ..$ alpha : logi NA
#>   ..$ stroke: num 0.5
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomPointrange   :List of 7
#>   ..$ colour  : chr "black"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ shape   : num 19
#>   ..$ fill    : logi NA
#>   ..$ alpha   : logi NA
#>   ..$ stroke  : num 1
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomPolygon      :List of 6
#>   ..$ colour  : chr "NA"
#>   ..$ fill    : chr "grey20"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..$ subgroup: NULL
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomQuantile     :List of 5
#>   ..$ weight  : num 1
#>   ..$ colour  : chr "#3366FF"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>  $ GeomRaster       :List of 2
#>   ..$ fill : chr "grey20"
#>   ..$ alpha: logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomRasterAnn    : Named list()
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomRect         :List of 5
#>   ..$ colour  : logi NA
#>   ..$ fill    : chr "grey35"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomRibbon       :List of 5
#>   ..$ colour  : logi NA
#>   ..$ fill    : chr "grey20"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomRug          :List of 4
#>   ..$ colour  : chr "black"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomSegment      :List of 4
#>   ..$ colour  : chr "black"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomSf           :List of 7
#>   ..$ shape   : NULL
#>   ..$ colour  : NULL
#>   ..$ fill    : NULL
#>   ..$ size    : NULL
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..$ stroke  : num 0.5
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomSmooth       :List of 6
#>   ..$ colour  : chr "#3366FF"
#>   ..$ fill    : chr "grey60"
#>   ..$ size    : num 1
#>   ..$ linetype: num 1
#>   ..$ weight  : num 1
#>   ..$ alpha   : num 0.4
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomSpoke        :List of 4
#>   ..$ colour  : chr "black"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomStep         :List of 4
#>   ..$ colour  : chr "black"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomText         :List of 9
#>   ..$ colour    : chr "black"
#>   ..$ size      : num 3.88
#>   ..$ angle     : num 0
#>   ..$ hjust     : num 0.5
#>   ..$ vjust     : num 0.5
#>   ..$ alpha     : logi NA
#>   ..$ family    : chr ""
#>   ..$ fontface  : num 1
#>   ..$ lineheight: num 1.2
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomTile         :List of 7
#>   ..$ fill    : chr "grey20"
#>   ..$ colour  : logi NA
#>   ..$ size    : num 0.1
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..$ width   : logi NA
#>   ..$ height  : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomViolin       :List of 6
#>   ..$ weight  : num 1
#>   ..$ colour  : chr "grey20"
#>   ..$ fill    : chr "white"
#>   ..$ size    : num 0.5
#>   ..$ alpha   : logi NA
#>   ..$ linetype: chr "solid"
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomVline        :List of 4
#>   ..$ colour  : chr "black"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
str(aes_list2)
#> List of 43
#>  $ Geom             : NULL
#>  $ GeomAbline       :List of 4
#>   ..$ colour  : chr "black"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomAnnotationMap: NULL
#>  $ GeomArea         :List of 5
#>   ..$ colour  : logi NA
#>   ..$ fill    : chr "grey20"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomBar          : NULL
#>  $ GeomBlank        : NULL
#>  $ GeomBoxplot      :List of 7
#>   ..$ weight  : num 1
#>   ..$ colour  : chr "grey20"
#>   ..$ fill    : chr "white"
#>   ..$ size    : num 0.5
#>   ..$ alpha   : logi NA
#>   ..$ shape   : num 19
#>   ..$ linetype: chr "solid"
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomCol          : NULL
#>  $ GeomContour      :List of 5
#>   ..$ weight  : num 1
#>   ..$ colour  : chr "#3366FF"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomCrossbar     :List of 5
#>   ..$ colour  : chr "black"
#>   ..$ fill    : logi NA
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomCurve        :List of 4
#>   ..$ colour  : chr "black"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomCustomAnn    :List of 4
#>   ..$ xmin: num -Inf
#>   ..$ xmax: num Inf
#>   ..$ ymin: num -Inf
#>   ..$ ymax: num Inf
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomDensity      :List of 6
#>   ..$ fill    : logi NA
#>   ..$ weight  : num 1
#>   ..$ colour  : chr "black"
#>   ..$ alpha   : logi NA
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>  $ GeomDensity2d    :List of 4
#>   ..$ colour  : chr "#3366FF"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomDotplot      :List of 5
#>   ..$ colour  : chr "black"
#>   ..$ fill    : chr "black"
#>   ..$ alpha   : logi NA
#>   ..$ stroke  : num 1
#>   ..$ linetype: chr "solid"
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomErrorbar     :List of 5
#>   ..$ colour  : chr "black"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ width   : num 0.5
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomErrorbarh    :List of 5
#>   ..$ colour  : chr "black"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ height  : num 0.5
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomHex          :List of 5
#>   ..$ colour  : logi NA
#>   ..$ fill    : chr "grey50"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomHline        :List of 4
#>   ..$ colour  : chr "black"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomLabel        :List of 10
#>   ..$ colour    : chr "black"
#>   ..$ fill      : chr "white"
#>   ..$ size      : num 3.88
#>   ..$ angle     : num 0
#>   ..$ hjust     : num 0.5
#>   ..$ vjust     : num 0.5
#>   ..$ alpha     : logi NA
#>   ..$ family    : chr ""
#>   ..$ fontface  : num 1
#>   ..$ lineheight: num 1.2
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomLine         : NULL
#>  $ GeomLinerange    :List of 4
#>   ..$ colour  : chr "black"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomLogticks     :List of 4
#>   ..$ colour  : chr "black"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : num 1
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomMap          : NULL
#>  $ GeomPath         :List of 4
#>   ..$ colour  : chr "black"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomPoint        :List of 6
#>   ..$ shape : num 19
#>   ..$ colour: chr "black"
#>   ..$ size  : num 1.5
#>   ..$ fill  : logi NA
#>   ..$ alpha : logi NA
#>   ..$ stroke: num 0.5
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomPointrange   :List of 7
#>   ..$ colour  : chr "black"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ shape   : num 19
#>   ..$ fill    : logi NA
#>   ..$ alpha   : logi NA
#>   ..$ stroke  : num 1
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomPolygon      :List of 6
#>   ..$ colour  : chr "NA"
#>   ..$ fill    : chr "grey20"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..$ subgroup: NULL
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomQuantile     :List of 5
#>   ..$ weight  : num 1
#>   ..$ colour  : chr "#3366FF"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>  $ GeomRaster       :List of 2
#>   ..$ fill : chr "grey20"
#>   ..$ alpha: logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomRasterAnn    : NULL
#>  $ GeomRect         :List of 5
#>   ..$ colour  : logi NA
#>   ..$ fill    : chr "grey35"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomRibbon       :List of 5
#>   ..$ colour  : logi NA
#>   ..$ fill    : chr "grey20"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomRug          :List of 4
#>   ..$ colour  : chr "black"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomSegment      :List of 4
#>   ..$ colour  : chr "black"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomSf           :List of 7
#>   ..$ shape   : NULL
#>   ..$ colour  : NULL
#>   ..$ fill    : NULL
#>   ..$ size    : NULL
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..$ stroke  : num 0.5
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomSmooth       :List of 6
#>   ..$ colour  : chr "#3366FF"
#>   ..$ fill    : chr "grey60"
#>   ..$ size    : num 1
#>   ..$ linetype: num 1
#>   ..$ weight  : num 1
#>   ..$ alpha   : num 0.4
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomSpoke        : NULL
#>  $ GeomStep         : NULL
#>  $ GeomText         :List of 9
#>   ..$ colour    : chr "black"
#>   ..$ size      : num 3.88
#>   ..$ angle     : num 0
#>   ..$ hjust     : num 0.5
#>   ..$ vjust     : num 0.5
#>   ..$ alpha     : logi NA
#>   ..$ family    : chr ""
#>   ..$ fontface  : num 1
#>   ..$ lineheight: num 1.2
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomTile         :List of 7
#>   ..$ fill    : chr "grey20"
#>   ..$ colour  : logi NA
#>   ..$ size    : num 0.1
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..$ width   : logi NA
#>   ..$ height  : logi NA
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomViolin       :List of 6
#>   ..$ weight  : num 1
#>   ..$ colour  : chr "grey20"
#>   ..$ fill    : chr "white"
#>   ..$ size    : num 0.5
#>   ..$ alpha   : logi NA
#>   ..$ linetype: chr "solid"
#>   ..- attr(*, "class")= chr "uneval"
#>  $ GeomVline        :List of 4
#>   ..$ colour  : chr "black"
#>   ..$ size    : num 0.5
#>   ..$ linetype: num 1
#>   ..$ alpha   : logi NA
#>   ..- attr(*, "class")= chr "uneval"

Created on 2019-07-15 by the reprex package (v0.3.0)

Right from the top when I run str(aes_list) and str(aes_list2) there's a difference in that the former gives (excerpting here):

str(aes_list)
#> List of 43
#>  $ Geom             : Named list()
#>   ..- attr(*, "class")= chr "uneval"

while the latter:

str(aes_list2)
#> List of 43
#>  $ Geom             : NULL

From the map() docs:

If .x has names() , the return value preserves those names.

which it does, but it's not capturing the next level of Geom as a named list (this is where I'm unsure about the expected behavior).

geoms$Geom
#> <ggproto object: Class Geom, gg>
#>     aesthetics: function
#>     default_aes: uneval
#>     draw_group: function
#>     draw_key: function
#>     draw_layer: function
#>     draw_panel: function
#>     extra_params: na.rm
#>     handle_na: function
#>     non_missing_aes: 
#>     optional_aes: 
#>     parameters: function
#>     required_aes: 
#>     setup_data: function
#>     use_defaults: function

Not sure if this helps, but I think the difference comes down to the implementation of the as_mapper() function. (Could be way off base here, just theorizing.)

The reprex below looks a the first two elements of the geoms list, which have different contents. Note that the return value from as_mapper.character is a bit different. The character variant returns NULL on the first element whereas the default variant returns an empty object.

library(tidyverse)

geom_names <- apropos("^Geom", ignore.case = FALSE)
geoms <- mget(geom_names, env = asNamespace("ggplot2"))
geoms <- geoms[1:2]

obj_geom_1 <- geoms[[1]]
obj_geom_2 <- geoms[[2]]

obj_geom_1$default_aes 
#> Aesthetic mapping: 
#> <empty>
obj_geom_2$default_aes
#> Aesthetic mapping: 
#> * `colour`   -> "black"
#> * `size`     -> 0.5
#> * `linetype` -> 1
#> * `alpha`    -> NA

my_mapper_2 <- as_mapper('default_aes')
my_mapper_3 <- as_mapper(`[[`)

my_mapper_2(obj_geom_1)
#> NULL
my_mapper_3(obj_geom_1, 'default_aes')
#> Aesthetic mapping: 
#> <empty>

my_mapper_2(obj_geom_2)
#> Aesthetic mapping: 
#> * `colour`   -> "black"
#> * `size`     -> 0.5
#> * `linetype` -> 1
#> * `alpha`    -> NA
my_mapper_3(obj_geom_2, 'default_aes')
#> Aesthetic mapping: 
#> * `colour`   -> "black"
#> * `size`     -> 0.5
#> * `linetype` -> 1
#> * `alpha`    -> NA

Created on 2019-07-18 by the reprex package (v0.3.0)

I think it comes down to the implementation of pluck(), which is what gets used by as_mapper.character(). The behavior is different than [[(). I've had a look at the C++, but there's no obvious smoking gun.

library(tidyverse)

geom_names <- apropos("^Geom", ignore.case = FALSE)
geoms <- mget(geom_names, env = asNamespace("ggplot2"))

obj_geom_1 <- geoms[[1]]

pluck(obj_geom_1, 'default_aes')
#> NULL
`[[`(obj_geom_1, 'default_aes')
#> Aesthetic mapping: 
#> <empty>

Created on 2019-07-18 by the reprex package (v0.3.0)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.