Skip to content

[Linting Rule] S3 Method Consistency

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.

S3 Method Consistency [overview]

bug cmd-check 38–39, 41 robustness

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

# Step Coverage Note
38 S3 generic/method consistency (book) 🟩⭐ ⭐ also apparent and unregistered methods without setting an environment variable
39 replacement functions (book) 🟩⭐ ⭐ also apparent replacement methods
41 use of S3 registration (book) 🔷 overwriting registered methods of standard packages is not checked

This rule is a best-effort rule.

Finds S3 methods whose formals do not match their generic, methods not registered in the NAMESPACE, and replacement functions whose last formal is not value.
This linting rule is implemented in src/linter/rules/cmd-check/s-three-method-consistency.ts.

Configuration

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

  • checkApparentMethods
    also check functions named like a method but not registered in the NAMESPACE, which R CMD check only does on request (default true)
    R CMD check #38
  • checkMethods
    check that methods take the arguments of their generic (default true)
    R CMD check #38
  • checkReplacementValues
    check that replacement functions end in value (default true)
    R CMD check #39
  • checkUnregistered
    report apparent methods of an exported generic that the NAMESPACE does not register (default true)
    R CMD check #41

Examples

print.myclass <- function(obj) cat("myclass")
`size<-` <- function(x, v) { attr(x, "size") <- v; x }

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

[ { "type": "linter",   "rules": [ { "name": "s3-method-consistency",     "config": {} } ] } ]

Results (prettified and summarized):

Query: linter (70 ms)
   ╰ S3 Method Consistency (s3-method-consistency):
       ╰ certain:
           ╰ size<-: replacement-value at 2.1-8

More examples are the test cases in test/functionality/linter/cmd-check/lint-s-three-method-consistency.test.ts.

Clone this wiki locally