Flags a call to options(), par() or setwd() that changes the user's
session state without restoring it.
Value
checktor_check_result() with passed, issues, message.
Source
The CRAN Cookbook covers this under
Change of Options, Graphical Parameters and Working Directory,
which asks that a function restore any options(), par() graphics parameters,
or working directory it changes, using on.exit(). No clause in the Repository
Policy or Writing R Extensions states it, yet it is among the most common reasons
a package is sent back, because a function that quietly runs options(digits = 3)
and returns has changed how the rest of the session behaves. See
vignette("check-sources", package = "checktor") for how every check maps to its
source.
Exemptions
Two shapes leak nothing and are exempt. A setter that captures the old value and
hands it back, as in old <- options(...); invisible(old), honours the base R
contract and lets the caller restore. And an option in the package's own
namespace, written options(<PackageName>.key = ...), is the package managing
its own configuration rather than the user's, so a deliberate session preference
like options(mypkg.threshold = 5) is fine. If you keep a user setting for the
session, give it a namespaced name rather than a bare global one, and restore a
genuinely temporary change with on.exit(options(old)).
See also
checktor(), which runs this and every other check.
Examples
pkg <- example_diagnose_scenario("code_examples/tf_usage_bad.R",
show_content = FALSE)
lab_option_changes(pkg, verbose = FALSE)$passed
#> [1] TRUE