Skip to contents

This article discusses how to customise the checks that are performed when sessioncheck() is called. The easiest way to alter its behavior is via the action argument, which specifies what action should be taken if an issue is detected (allowed values: "warn", "error", "message", "none"), and via the checks argument, which specifies which checks should be performed. The default behaviour corresponds to this:

sessioncheck::sessioncheck(
  action = "warn",
  checks = c(
    "globalenv_objects", 
    "attached_packages", 
    "attached_environments"
  )
)

In this case, three checks are performed:

Several other options can be specified:

For example, this checks the loaded namespaces only:

sessioncheck::sessioncheck(
  action = "warn",
  checks = "loaded_namespaces"
)
#> Warning: Session check results:
#> - Loaded namespaces: digest, desc, R6, fastmap, and 19 more

The individual checks can themselves be customized. Each check function has one extra argument that is used to control its behavior, and these can be passed to the check function via .... For example, you can do this:

sessioncheck::sessioncheck(
  action = "warn",
  checks = c("loaded_namespaces", "required_options"),
  allow_loaded_namespaces = c("knitr", "vctrs", "cli"),
  required_options = list(scipen = 0L, max.print = 50L)
)
#> Warning: Session check results:
#> - Loaded namespaces: digest, desc, R6, fastmap, and 17 more
#> - Unexpected options: max.print

The relevant arguments that can be passed via ... are as follows:

To make life a little easier, the default values for all arguments can be specified via options(). For example, you could include something like this in the .Rprofile:

options(
  sessioncheck = list(
    action = "message",
    checks = c("loaded_namespaces", "required_options"),
    allow_loaded_namespaces = c("knitr", "vctrs", "cli"),
    required_options = list(scipen = 0L, max.print = 50L)
  )
)

When called, sessioncheck() will now use these values:

sessioncheck::sessioncheck()
#> Session check results:
#> - Loaded namespaces: digest, desc, R6, fastmap, and 17 more
#> - Unexpected options: max.print

For more information on the specifics of each check, please see the documentation of the relevant check function or the article on individual checks.