In this example in the Code Issues section, add = TRUE is not specified when setting multiple on.exit() calls. This will lead to a the first two on.exit code snippets not being executed and thus failing to reset to the pre-specified par/option settings at the end of the function.
foo <- function(x){
# par():
oldpar <- par(mfrow = c(2,2))
on.exit(par(oldpar))
# options():
oldop <- options(digits = 3)
on.exit(options(oldop))
# setwd():
oldwd <- setwd(".")
on.exit(setwd(oldwd))
# your code which requires a changed option
}
This should be changed to the following:
foo <- function(x){
# par():
oldpar <- par(mfrow = c(2,2))
on.exit(par(oldpar))
# options():
oldop <- options(digits = 3)
on.exit(options(oldop), add = TRUE)
# setwd():
oldwd <- setwd(".")
on.exit(setwd(oldwd), add = TRUE)
# your code which requires a changed option
}