Repository navigation
[Linting Rule] Class String Comparison
Generated from 'wiki-linter.ts' on 2026-10-25, 09:29:25 UTC (v2.16.6), do not edit directly.
Class String Comparison [overview]
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 if/while conditions comparing class(x) with a string, which fail for objects with several classes. Offers inherits(x, ...) as a quick fix.
This linting rule is implemented in src/linter/rules/cmd-check/class-string-comparison.ts.
Linting rules can be configured by passing a configuration object to the linter query as shown in the example below.
The class-string-comparison rule accepts the following configuration options:
-
checkWhile
also check the conditions ofwhileloops, whichR CMD checkdoes not (defaulttrue)
R CMD check #37 -
resolveStrings
also flag a comparison with a variable flowR resolves to a string, whichR CMD checkcannot see (defaulttrue)
R CMD check #37
f <- function(x) if(class(x) == "data.frame") nrow(x) else length(x)The linting query can be used to run this rule on the above example:
[ { "type": "linter", "rules": [ { "name": "class-string-comparison", "config": {} } ] } ]Results (prettified and summarized):
Query: linter (2 ms)
╰ Class String Comparison (class-string-comparison):
╰ certain:
╰ class() compared to "data.frame" at 1.21-44 (1 quick fix(es) available)
More examples are the test cases in test/functionality/linter/cmd-check/lint-class-string-comparison.test.ts.
Currently maintained by Florian Sihler and Oliver Gerstl at Ulm University
Email | GitHub | Penguins | Portfolio
- 🧑💻 Developer Onboarding
- 💻 Setup
- 👓 Overview
- 🪟 Interfacing with flowR
- 🌋 Core
- 🧹 Testing & Linting (Benchmark Page)
⁉️ FAQ- ℹ️ Extra Information