Skip to content

Linter for length(x == y) where almost certainly length(which(x == y)) or length(x) == y was intended #1991

@MichaelChirico

Description

@MichaelChirico

This is a mistake that I find myself making all the time:

if (length(x == 0)) ...

It makes itself into a really subtle bug and many wasted minutes.

I can't think of a case where length(x == y) is preferable to length(x) or length(y), unless there's some weird coercion going on and that should be made explicit anyway.

Therefore it seems like a good candidate for a new linter.

I don't really know what to name such a linter... I also wonder if maybe it's good for an umbrella linter like common_mistakes_linter(), though I can't really think of other good candidate rules for that off the top of my head. see comment below

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions