R/utilities-help.r

Defines functions rd_aesthetics rd_aesthetics_item

rd_aesthetics <- function(type, name) {
  obj <- switch(type,
    geom = find_subclass("Geom", name, globalenv()),
    stat = find_subclass("Stat", name, globalenv())
  )
  aes <- rd_aesthetics_item(obj)

  c(
    "@section Aesthetics:",
    paste0(
      "\\code{", type, "_", name, "} ",
      "understands the following aesthetics (required aesthetics are in bold):"
    ),
    "\\itemize{",
    paste0("  \\item ", aes),
    "}",
    "Learn more about setting these aesthetics in \\code{vignette(\"ggplot2-specs\")}"
  )
}

rd_aesthetics_item <- function(x) {
  req <- x$required_aes
  all <- union(req, sort(x$aesthetics()))

  ifelse(all %in% req,
    paste0("\\strong{\\code{", all, "}}"),
    paste0("\\code{", all, "}")
  )
}
SahaRahul/ggplot2 documentation built on May 17, 2019, 1:46 p.m.