@@ -12,11 +12,10 @@ rd_aesthetics <- function(type, name, extra_note = NULL) {
1212 " @section Aesthetics:" ,
1313 paste0(
1414 " \\ code{" , type , " _" , name , " ()} " ,
15- " understands the following aesthetics (required aesthetics are in bold):"
15+ " understands the following aesthetics. Required aesthetics are displayed" ,
16+ " in bold and defaults are displayed for optional aesthetics:"
1617 ),
17- " \\ itemize{" ,
18- paste0(" \\ item " , aes ),
19- " }" ,
18+ " \\ tabular{rll}{" , aes , " }" ,
2019 if (! is.null(extra_note )) paste0(extra_note , " \n " ),
2120 " Learn more about setting these aesthetics in \\ code{vignette(\" ggplot2-specs\" )}."
2221 )
@@ -29,11 +28,34 @@ rd_aesthetics_item <- function(x) {
2928 optional_aes <- setdiff(x $ aesthetics(), req_aes )
3029 all <- union(req , sort(optional_aes ))
3130 docs <- rd_match_docpage(all )
31+ defaults <- rd_defaults(x , all )
3232
3333 item <- ifelse(all %in% req ,
3434 paste0(" \\ strong{\\ code{" , docs , " }}" ),
3535 paste0(" \\ code{" , docs , " }" )
3636 )
37+ paste0(" \u 2022 \\ tab " , item , " \\ tab " , defaults , " \\ cr\\ cr" )
38+ }
39+
40+ rd_defaults <- function (layer , aesthetics ) {
41+ defaults <- layer $ default_aes
42+
43+ out <- rep(" " , length(aesthetics ))
44+
45+ themed <- vapply(defaults , FUN.VALUE = logical (1 ), function (x ) {
46+ is_quosure(x ) && quo_is_call(x , name = " from_theme" )
47+ })
48+ defaults <- lapply(defaults , quo_text )
49+ defaults [themed ] <- " via \\ code{theme()}"
50+ defaults [! themed ] <- paste0(" \\ code{" , defaults [! themed ], " }" )
51+
52+ i <- intersect(aesthetics , names(defaults ))
53+ out [match(i , aesthetics )] <- defaults [i ]
54+ empty <- ! nzchar(out )
55+ out [! empty ] <- paste0(" \u 2192 " , out [! empty ])
56+ out [empty ] <- " "
57+ out [empty & aesthetics == " group" ] <- " \u 2192 inferred"
58+ out
3759}
3860
3961rd_match_docpage <- function (aes ) {
0 commit comments