Skip to content

New linter for if(all.equal(...)) #2610

@MichaelChirico

Description

@MichaelChirico

all.equal() has a strange return pattern -- it's TRUE on "success", but typically character (at least in all the base methods) on "failure".

Therefore it's inappropriate to test if(all.equal(...)) -- instead we should use if(isTRUE(all.equal(...))).

Here's a couple hundred hits in CRAN packages using if(all.equal(...)):

https://github.com/search?q=org%3Acran%20lang%3AR%20%2Fif%5Cs*%5C(%5Cs*all%5B.%5Dequal%5C(%2F&type=code

Note that this advice is very explicit in ?all.equal:

Do not use all.equal directly in if expressions—either use isTRUE(all.equal(....)) or identical if appropriate.

Filed as a new linter since no existing linter comes to mind that would accommodate this. Closest is maybe vector_logic_linter() but it's too far a stretch IMO.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions