Skip to content

[Linting Rule] Global Environment Modification

github-actions[bot] edited this page Oct 25, 2026 · 1 revision

Generated from 'wiki-linter.ts' on 2026-10-25, 09:29:25 UTC (v2.16.6), do not edit directly.

Global Environment Modification [overview]

bug cmd-check 37 robustness

This rule ports the following steps of R CMD check (see the conformance table for the legend):

# Step Coverage Note
37 R code for possible problems (book) 🟩⭐ ⭐ also quick fixes, deprecated arguments, environments resolved through variables, hooks followed into callees

This rule is a best-effort rule.

Finds code that changes the global environment: assign() or data() into it, attach(), <<- without a binding in an enclosing function, and <<- to a package variable, whose binding is locked at run time.
This linting rule is implemented in src/linter/rules/cmd-check/global-environment-modification.ts.

Configuration

Linting rules can be configured by passing a configuration object to the linter query as shown in the example below. The global-environment-modification rule accepts the following configuration options:

  • allowedGlobals
    variables that may be assigned in the global environment (default .Random.seed, as R CMD check allows)
    R CMD check #37
  • checkSuperAssignments
    report <<- assignments that reach the global environment or a locked namespace binding (default true)
    R CMD check #37

Examples

cache <- function(v) assign("cached", v, envir = globalenv())
count <- function() counter <<- counter + 1

The linting query can be used to run this rule on the above example:

[ { "type": "linter",   "rules": [ { "name": "global-environment-modification",     "config": {} } ] } ]

Results (prettified and summarized):

Query: linter (3 ms)
   ╰ Global Environment Modification (global-environment-modification):
       ╰ certain:
           ╰ assign of cached at 1.22-61
           ╰ global-superassignment of counter at 2.21-43

More examples are the test cases in test/functionality/linter/cmd-check/lint-global-environment-modification.test.ts.

Clone this wiki locally