Skip to content

Commit

Permalink
shutdown graphical devices
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Nov 21, 2024
1 parent 50a36d7 commit fd19483
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 3 additions & 0 deletions R/tinytheme.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#' Set or Reset Plot Themes for `tinyplot`
#'
#' @description
#' The `tinytheme` function sets or resets the theme for plots created with
#' `tinyplot`. Themes control the appearance of plots, such as text alignment,
#' font styles, and axis labels. By default, a "bw" theme is available.
#'
#' Warning: `tinytheme()` shuts down all open graphical devices.
#'
#' @param theme A character string specifying the name of the theme to apply.
#' - `"default"`
#' - `"bw"`
Expand Down
10 changes: 5 additions & 5 deletions R/tpar.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,7 @@ tpar = function(..., hook = FALSE, init = FALSE) {
base_par = setdiff(nam, known_tpar)
base_par = opts[base_par]
if (isTRUE(hook)) {
tpar_hook = function() {
par(base_par)
}
setHook("before.plot.new", tpar_hook, action = "replace")
setHook("before.plot.new", NULL, action = "replace")
par(base_par)
} else {
par(base_par)
Expand All @@ -166,6 +163,7 @@ tpar = function(..., hook = FALSE, init = FALSE) {
}
if (!is.null(opts) && length(opts) != 0) {
# specific values requested
opts = Filter(is.character, opts)
ret = (`names<-`(lapply(opts, function(x) .tpar[[x]]), opts))
if (length(used_par)) {
ret_par = par(used_par)
Expand Down Expand Up @@ -298,10 +296,12 @@ assert_tpar = function(.tpar) {
init_tpar = function(rm_hook = FALSE) {
rm(list = names(.tpar), envir = .tpar)

grDevices::graphics.off()

if (isTRUE(rm_hook)) {
hook = getHook("before.plot.new")
if (length(hook) > 0) {
setHook("before.plot.new", function(...) return(invisible(NULL)), action = "replace")
setHook("before.plot.new", NULL, action = "replace")
}
}

Expand Down

0 comments on commit fd19483

Please sign in to comment.