Skip to contents

Individual session check function that inspects the contents of the global environment. Session checkers can produce errors, warnings, or messages if requested.

Usage

check_globalenv_objects(
  action = "warn",
  allow_globalenv_objects = NULL,
  action_on_pass = "none"
)

Arguments

action

Behavior to take if the status is not clean. Possible values are "error", "warn", "message", and "none". The default is action = "warn".

allow_globalenv_objects

Character vector containing names of objects that are "allowed", and will not trigger an action. The default is allow_globalenv_objects = NULL, in which case dot-prefixed objects (e.g. .Random.seed) are allowed.

action_on_pass

Behavior to take if the status is clean. Possible values are "message" and "none". The default is action_on_pass = "none".

Value

Invisibly returns an object of class sessioncheck_status.

Details

This checker inspects the state of the global environment and takes action based on the objects found there. When allow_globalenv_objects = NULL, variables in the global environment will not trigger an action if the name starts with a dot. For example, .Random.seed and .Last.value do not trigger actions by default.

Examples

check_globalenv_objects(action = "message")

# a session with no unexpected objects in the global environment:
# `action` only controls what happens when a problem *is* found, so use
# `action_on_pass = "message"` to confirm the clean result instead
check_globalenv_objects(
  action = "none",
  allow_globalenv_objects = ls(envir = .GlobalEnv, all.names = TRUE),
  action_on_pass = "message"
)
#>  No unexpected objects in global environment