aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2021-02-24 14:46:10 +0100
committerJohannes Ranke <jranke@uni-bremen.de>2021-02-24 14:58:04 +0100
commit64fa10032f99490a5998589161574109484ee769 (patch)
tree74c47a1c8d36a1b164029f808b6075f61d2ab43a
parent7f35f5d98968f059176f4c339e1db8f17d5c4bf1 (diff)
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.
-rw-r--r--R/mkinparplot.R4
-rw-r--r--R/plot.mixed.mmkin.R1
-rw-r--r--R/plot.mkinfit.R2
-rw-r--r--R/plot.mmkin.R3
-rw-r--r--tests/figs/plotting/mixed-model-fit-for-mmkin-object.svg5
-rw-r--r--tests/figs/plotting/mixed-model-fit-for-nlme-object.svg5
6 files changed, 15 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 5a0b7412..4c1f1531 100644
--- a/R/plot.mixed.mmkin.R
+++ b/R/plot.mixed.mmkin.R
@@ -146,6 +146,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)
}
diff --git a/tests/figs/plotting/mixed-model-fit-for-mmkin-object.svg b/tests/figs/plotting/mixed-model-fit-for-mmkin-object.svg
index e022af25..b3abac39 100644
--- a/tests/figs/plotting/mixed-model-fit-for-mmkin-object.svg
+++ b/tests/figs/plotting/mixed-model-fit-for-mmkin-object.svg
@@ -710,4 +710,9 @@
<polyline points='531.56,398.39 534.08,395.87 536.60,398.39 534.08,400.91 531.56,398.39 ' style='stroke-width: 0.75; stroke: #CD0BBC;' clip-path='url(#cpMzk4Ljk3fDcwMC4wNHw1MjcuNTN8MzA2LjEw)' />
<polyline points='542.22,397.33 544.74,394.81 547.26,397.33 544.74,399.85 542.22,397.33 ' style='stroke-width: 0.75; stroke: #CD0BBC;' clip-path='url(#cpMzk4Ljk3fDcwMC4wNHw1MjcuNTN8MzA2LjEw)' />
<polyline points='542.22,430.83 544.74,428.31 547.26,430.83 544.74,433.35 542.22,430.83 ' style='stroke-width: 0.75; stroke: #CD0BBC;' clip-path='url(#cpMzk4Ljk3fDcwMC4wNHw1MjcuNTN8MzA2LjEw)' />
+<defs>
+ <clipPath id='cpNTkuMDR8Njg5Ljc2fDUwMi41Nnw1OS4wNA=='>
+ <rect x='59.04' y='59.04' width='630.72' height='443.52' />
+ </clipPath>
+</defs>
</svg>
diff --git a/tests/figs/plotting/mixed-model-fit-for-nlme-object.svg b/tests/figs/plotting/mixed-model-fit-for-nlme-object.svg
index b2955239..3eb2b0f8 100644
--- a/tests/figs/plotting/mixed-model-fit-for-nlme-object.svg
+++ b/tests/figs/plotting/mixed-model-fit-for-nlme-object.svg
@@ -1348,4 +1348,9 @@
<polygon points='464.66,238.64 469.14,238.64 469.14,234.16 464.66,234.16 ' style='stroke-width: 0.75; stroke: none; fill: #9E9E9E;' clip-path='url(#cpNDA5LjAwfDY5NC45MHw1MTUuMDR8MTQ2LjA3)' />
<polygon points='449.43,276.29 453.91,276.29 453.91,271.81 449.43,271.81 ' style='stroke-width: 0.75; stroke: none; fill: #9E9E9E;' clip-path='url(#cpNDA5LjAwfDY5NC45MHw1MTUuMDR8MTQ2LjA3)' />
<polygon points='449.43,366.64 453.91,366.64 453.91,362.16 449.43,362.16 ' style='stroke-width: 0.75; stroke: none; fill: #9E9E9E;' clip-path='url(#cpNDA5LjAwfDY5NC45MHw1MTUuMDR8MTQ2LjA3)' />
+<defs>
+ <clipPath id='cpNTkuMDR8Njg5Ljc2fDUwMi41Nnw1OS4wNA=='>
+ <rect x='59.04' y='59.04' width='630.72' height='443.52' />
+ </clipPath>
+</defs>
</svg>

Contact - Imprint