| 1 |
#' @include with_.R |
| 2 |
NULL |
| 3 |
|
| 4 |
# par ------------------------------------------------------------------------ |
| 5 |
|
| 6 |
get_par <- function(...) { |
| 7 |
new <- auto_splice(list(...)) |
| 8 |
if (length(new) == 0) { |
| 9 |
# Only retrieve settable values |
| 10 |
out <- graphics::par(no.readonly = TRUE) |
| 11 |
} else { |
| 12 |
out <- do.call(graphics::par, as.list(names(new))) |
| 13 |
} |
| 14 |
|
| 15 |
# `par()` doesn't wrap in a list if input is length 1 |
| 16 |
if (length(new) == 1) { |
| 17 |
out <- list(out) |
| 18 |
names(out) <- names(new) |
| 19 |
} |
| 20 |
|
| 21 |
out |
| 22 |
} |
| 23 |
|
| 24 |
# `get_par()` must have exactly the same signature as `par()` to be |
| 25 |
# compatible with `with_()` and `local_()` |
| 26 |
formals(get_par) <- formals(graphics::par) |
| 27 |
|
| 28 |
#' Graphics parameters |
| 29 |
#' |
| 30 |
#' Temporarily change graphics parameters. |
| 31 |
#' |
| 32 |
#' @template with |
| 33 |
#' @param new,.new `[named list]`\cr New graphics parameters and their values |
| 34 |
#' @param no.readonly `[logical(1)]`\cr see [par()] documentation. |
| 35 |
#' @param ... Additional graphics parameters and their values. |
| 36 |
#' @inheritParams with_collate |
| 37 |
#' @seealso [par()] |
| 38 |
#' @export |
| 39 |
#' @examples |
| 40 |
#' old <- par("col" = "black") |
| 41 |
#' |
| 42 |
#' # This will be in red |
| 43 |
#' with_par(list(col = "red", pch = 19), |
| 44 |
#' plot(mtcars$hp, mtcars$wt) |
| 45 |
#' ) |
| 46 |
#' |
| 47 |
#' # This will still be in black |
| 48 |
#' plot(mtcars$hp, mtcars$wt) |
| 49 |
#' |
| 50 |
#' par(old) |
| 51 |
with_par <- with_(graphics::par, get = get_par) |
| 52 |
|
| 53 |
#' @rdname with_par |
| 54 |
#' @export |
| 55 |
local_par <- local_(graphics::par, get = get_par, dots = TRUE) |