From 28c0dff7d7191f854be610b5384e965d9b191f98 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Wed, 24 Feb 2021 14:46:10 +0100 Subject: Reset graphical parameters with on.exit() plot.mixed.mmkin did not reset graphical parameters at all. The other plotting functions did not use on.exit, so this change should make the use of the plotting functions safer. --- R/mkinparplot.R | 4 ++-- R/plot.mixed.mmkin.R | 1 + R/plot.mkinfit.R | 2 +- R/plot.mmkin.R | 3 +-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/R/mkinparplot.R b/R/mkinparplot.R index f9abab5b..8cae30fb 100644 --- a/R/mkinparplot.R +++ b/R/mkinparplot.R @@ -32,7 +32,8 @@ mkinparplot <- function(object) { fractions.optim = length(fractions.optim)) n.plot <- n.plot[n.plot > 0] - oldpars <- par(no.readonly = TRUE) + oldpar <- par(no.readonly = TRUE) + on.exit(par(oldpar, no.readonly = TRUE)) layout(matrix(1:length(n.plot), ncol = 1), heights = n.plot + 1) s <- summary(object) @@ -71,5 +72,4 @@ mkinparplot <- function(object) { as.numeric(values.upper.nonInf), parname_index, code = 3, angle = 90, length = 0.05)) } - par(oldpars) } diff --git a/R/plot.mixed.mmkin.R b/R/plot.mixed.mmkin.R index 1674d855..21399496 100644 --- a/R/plot.mixed.mmkin.R +++ b/R/plot.mixed.mmkin.R @@ -167,6 +167,7 @@ plot.mixed.mmkin <- function(x, # Start of graphical section oldpar <- par(no.readonly = TRUE) + on.exit(par(oldpar, no.readonly = TRUE)) n_plot_rows = length(obs_vars) n_plots = n_plot_rows * 2 diff --git a/R/plot.mkinfit.R b/R/plot.mkinfit.R index eced40a4..2e319aae 100644 --- a/R/plot.mkinfit.R +++ b/R/plot.mkinfit.R @@ -161,6 +161,7 @@ plot.mkinfit <- function(x, fit = x, if (do_layout) { # Layout should be restored afterwards oldpar <- par(no.readonly = TRUE) + on.exit(par(oldpar, no.readonly = TRUE)) # If the observed variables are shown separately, or if requested, do row layout if (sep_obs | row_layout) { @@ -287,7 +288,6 @@ plot.mkinfit <- function(x, fit = x, legend = FALSE, frame = frame) } } - if (do_layout) par(oldpar, no.readonly = TRUE) } #' @rdname plot.mkinfit diff --git a/R/plot.mmkin.R b/R/plot.mmkin.R index f8ed1f9a..2166b30e 100644 --- a/R/plot.mmkin.R +++ b/R/plot.mmkin.R @@ -65,6 +65,7 @@ plot.mmkin <- function(x, main = "auto", legends = 1, { oldpar <- par(no.readonly = TRUE) + on.exit(par(oldpar, no.readonly = TRUE)) n.m <- nrow(x) n.d <- ncol(x) @@ -153,6 +154,4 @@ plot.mmkin <- function(x, main = "auto", legends = 1, } mtext(paste(fit_name, "residuals"), cex = cex, line = 0.4) } - - par(oldpar, no.readonly = TRUE) } -- cgit v1.2.1