diff --git a/.lintr b/.lintr
index 5f69e9d88..411582fde 100644
--- a/.lintr
+++ b/.lintr
@@ -10,8 +10,7 @@ linters: all_linters(
default_undesirable_functions,
citEntry = "use the more modern bibentry() function",
library = NULL, # too many false positive in too many files
- structure = NULL, # used for class constructor functions
- par = NULL # used with on.exit() and {withrs} is not a dependency
+ structure = NULL # used for class constructor functions
)
),
function_argument_linter = NULL,
diff --git a/R/plot.R b/R/plot.R
index e337eb872..f3804b8ea 100644
--- a/R/plot.R
+++ b/R/plot.R
@@ -52,9 +52,6 @@ plot.epiparameter <- function(x,
# capture dots
dots <- list(...)
- oldpar <- graphics::par(no.readonly = TRUE)
- on.exit(graphics::par(oldpar))
-
if (is_continuous(x)) {
main <- "Probability Density Function"
} else {
diff --git a/tests/testthat/_snaps/epiparameter/epiparameter-plot-non-default-range.svg b/tests/testthat/_snaps/epiparameter/epiparameter-plot-non-default-range.svg
index 4f16c78aa..3dde075be 100644
--- a/tests/testthat/_snaps/epiparameter/epiparameter-plot-non-default-range.svg
+++ b/tests/testthat/_snaps/epiparameter/epiparameter-plot-non-default-range.svg
@@ -56,6 +56,4 @@
Probability Density Function
Incubation
-
-
diff --git a/tests/testthat/_snaps/epiparameter/epiparameter-plot-units.svg b/tests/testthat/_snaps/epiparameter/epiparameter-plot-units.svg
index 56acbbdae..c9966660a 100644
--- a/tests/testthat/_snaps/epiparameter/epiparameter-plot-units.svg
+++ b/tests/testthat/_snaps/epiparameter/epiparameter-plot-units.svg
@@ -56,6 +56,4 @@
Probability Density Function
Incubation (Days)
-
-
diff --git a/tests/testthat/_snaps/epiparameter/epiparameter-plot.svg b/tests/testthat/_snaps/epiparameter/epiparameter-plot.svg
index bdbd1e2e6..0bb9e4e82 100644
--- a/tests/testthat/_snaps/epiparameter/epiparameter-plot.svg
+++ b/tests/testthat/_snaps/epiparameter/epiparameter-plot.svg
@@ -56,6 +56,4 @@
Probability Density Function
Incubation
-
-
diff --git a/tests/testthat/test-epiparameter.R b/tests/testthat/test-epiparameter.R
index 69a4baaa3..e892096d5 100644
--- a/tests/testthat/test-epiparameter.R
+++ b/tests/testthat/test-epiparameter.R
@@ -174,6 +174,8 @@ test_that("epiparameter fails as expected", {
})
test_that("epiparameter.plot does not produce an error", {
+ # plotting changes global state of graphics pars so they are restored
+ op <- par(no.readonly = TRUE)
ebola_dist <- suppressMessages(epiparameter(
disease = "ebola",
epi_name = "incubation",
@@ -182,18 +184,19 @@ test_that("epiparameter.plot does not produce an error", {
prob_distribution_params = c(shape = 1, scale = 1)
)
))
-
-
expect_silent(plot(ebola_dist))
-
f <- function() plot(ebola_dist)
vdiffr::expect_doppelganger(
title = "epiparameter.plot",
fig = f
)
+ # restore graphics pars
+ par(op)
})
test_that("epiparameter.plot prints units in x-axis", {
+ # plotting changes global state of graphics pars so they are restored
+ op <- par(no.readonly = TRUE)
ebola_dist <- suppressMessages(epiparameter(
disease = "ebola",
epi_name = "incubation",
@@ -203,18 +206,19 @@ test_that("epiparameter.plot prints units in x-axis", {
),
metadata = create_metadata(units = "days")
))
-
-
expect_silent(plot(ebola_dist))
-
f <- function() plot(ebola_dist)
vdiffr::expect_doppelganger(
title = "epiparameter.plot units",
fig = f
)
+ # restore graphics pars
+ par(op)
})
test_that("epiparameter.plot works with non-default x-axis", {
+ # plotting changes global state of graphics pars so they are restored
+ op <- par(no.readonly = TRUE)
ebola_dist <- suppressMessages(epiparameter(
disease = "ebola",
epi_name = "incubation",
@@ -223,14 +227,12 @@ test_that("epiparameter.plot works with non-default x-axis", {
prob_distribution_params = c(shape = 1, scale = 1)
)
))
-
expect_silent(
plot(
ebola_dist,
xlim = c(0, 20)
)
)
-
f <- function() {
plot(
ebola_dist,
@@ -241,6 +243,8 @@ test_that("epiparameter.plot works with non-default x-axis", {
title = "epiparameter.plot non-default range",
fig = f
)
+ # restore graphics pars
+ par(op)
})
test_that("new_epiparameter works with minimal viable input", {