R/s3-ggplot2-Guides.R

Defines functions .cstr_construct.Guides.guides is_corrupted_Guides .cstr_construct.Guides opts_Guides

Documented in opts_Guides

#' Constructive options for class 'Guides'
#'
#' These options will be used on objects of class 'Guides'.
#'
#' Depending on `constructor`, we construct the object as follows:
#' * `"guides"` (default): We build the object using `ggplot2::guides()`.
#' * `"next"` : Use the constructor for the next supported class.
#'
#' @param constructor String. Name of the function used to construct the object.
#' @param ... Additional options used by user defined constructors through the `opts` object
#' @return An object of class <constructive_options/constructive_options_Guides>
#' @export
opts_Guides <- function(constructor = c("guides", "next"), ...) {
  constructive::.cstr_options("Guides", constructor = constructor[[1]], ...)
}

#' @exportS3Method constructive::.cstr_construct
.cstr_construct.Guides <- function(x, ...) {
  opts <- list(...)$opts$Guides %||% opts_Guides()
  if (is_corrupted_Guides(x) || opts$constructor == "next") return(NextMethod())
  UseMethod(".cstr_construct.Guides", structure(NA, class = opts$constructor))
}

is_corrupted_Guides <- function(x) {
  FALSE
}

#' @export
.cstr_construct.Guides.guides <- function(x, ...) {
  args <- x$guides
  code <- constructive::.cstr_apply(args, fun = "ggplot2::guides", ...)
  constructive::.cstr_repair_attributes(
    x, code, ...,
    idiomatic_class = c("Guides", "ggproto", "gg")
  )
}

Try the constructive package in your browser

Any scripts or data that you put into this service are public.

constructive documentation built on Nov. 5, 2025, 7:14 p.m.