Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plot options #121

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ S3method(repr_vegalite2,vegalite)
export(format2repr)
export(html_dependencies)
export(mime2repr)
export(plot_options)
export(repr)
export(repr_geojson)
export(repr_html)
Expand Down
42 changes: 30 additions & 12 deletions R/options.r
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
#' repr options
#'
#' These options are used to control the behavior of repr when not calling it directly. Use \code{\link[base]{options}(repr.* = ...)} and \code{\link[base]{getOption}('repr.*')} to set and get them, respectively.
#' These options are used to control the behavior of repr when not calling it directly.
#' Use \code{\link[base]{options}(repr.* = ...)} and \code{\link[base]{getOption}('repr.*')}
#' to set and get them, respectively.
#' \code{plot_options} is a convenience function to reset the plot to defaults (overriding some)
#'
#' Once this package is loaded, all options are set to defaults which weren’t set beforehand.
#'
#' Setting all options set to \code{NULL} are reset to defaults when reloading the package (or calling \code{repr:::.onload()}).
#'
#' @param width Plotting area width in inches (default: 7)
#' @param height Plotting area height in inches (default: 7)
#' @param pointsize Text height in pt (default: 12)
#' @param bg Background color (default: white)
#' @param antialias Which kind of antialiasing to use for for lines and text? 'gray', 'subpixel' or 'none'? (default: gray)
#' @param res PPI for rasterization (default: 120)
#' @param quality Quality of JPEG format in \% (default: 90)
#' @param family Vector font family. 'sans', 'serif', 'mono' or a specific one (default: sans)
#'
#' @section Options:
#'
#' \describe{
#'
#' \item{\code{repr.plot.*}}{
#' Those are for representations of \code{recordedplot} instances:
#' \describe{
#' \item{\code{repr.plot.width}}{Plotting area width in inches (default: 7)}
#' \item{\code{repr.plot.height}}{Plotting area height in inches (default: 7)}
#' \item{\code{repr.plot.pointsize}}{Text height in pt (default: 12)}
#' \item{\code{repr.plot.bg}}{Background color (default: white)}
#' \item{\code{repr.plot.antialias}}{Which kind of antialiasing to use for for lines and text? 'gray', 'subpixel' or 'none'? (default: gray)}
#' \item{\code{repr.plot.res}}{PPI for rasterization (default: 120)}
#' \item{\code{repr.plot.quality}}{Quality of JPEG format in \% (default: 90)}
#' \item{\code{repr.plot.family}}{Vector font family. 'sans', 'serif', 'mono' or a specific one (default: sans)}
#' }
#' Those are for representations of \code{recordedplot} instances. See \emph{Arguments}
#' }
#' \item{\code{repr.vector.quote}}{
#' Output quotation marks for character vectors? (default: TRUE)
Expand Down Expand Up @@ -74,6 +76,22 @@ class_defaults <- list(
#' @export
repr_option_defaults <- c(plot_defaults, class_defaults)


#' @name repr-options
#' @export
plot_options <- function(...) {
env <- environment()
arg_names <- formalArgs(plot_options)
arg_spec <- sapply(arg_names, get, env)
names(arg_spec) <- paste0('repr.plot.', arg_names)
do.call(options, arg_spec)
}
formals(plot_options) <- local({
args <- plot_defaults
names(args) <- sub('^repr[.]plot[.]', '', names(args))
as.pairlist(args)
})

.onLoad <- function(libname = NULL, pkgname = NULL) {
for (opt_name in names(repr_option_defaults)) {
if (is.null(getOption(opt_name)))
Expand Down
33 changes: 22 additions & 11 deletions man/repr-options.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.