R Under development (unstable) (2025-12-16 r89184 ucrt) -- "Unsuffered Consequences" Copyright (C) 2025 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > message("*** withPar() ...") *** withPar() ... > > library("R.devices") R.devices v2.17.3 successfully loaded. See ?R.devices for help. > > x <- 1 > message("x=", x) x=1 > > withPar({ + layout(1:4) + + x <- c(x, 2) + message("x=", x) + stopifnot(all(x == 1:2)) + + withPar({ + plot(1:10) + plot(10:1) + x <- c(x, 3) + message("x=", x) + }, pch=4) + message("x=", x) + stopifnot(all(x == 1:3)) + + withPar({ + plot(1:10) + plot(10:1) + x <- c(x, 4) + message("x=", x) + }, pch=0, bg="yellow") + message("x=", x) + stopifnot(all(x == 1:4)) + + x <- c(x, 5) + message("x=", x) + stopifnot(all(x == 1:5)) + }, mar=c(2,2,1,1)) x=12 x=123 x=123 x=1234 x=1234 x=12345 > > message("x=", x) x=12345 > stopifnot(all(x == 1:5)) > > > # Graphical parameters set "manually" are also reset > opar <- par() > withPar({ + par(pch=4L, lwd=3) + plot(1:10) + }) > stopifnot(all.equal(par(), opar)) > > message("*** withPar() ... DONE") *** withPar() ... DONE > > proc.time() user system elapsed 0.45 0.12 0.56