Skip to content

seq_linter() gives the wrong message for n:1 lints #1542

Closed

Description

@MichaelChirico

The result message should mention rev(), but currently it doesn't:

lint(text = ".N:1", linters = seq_linter())
# <text>:1:1: warning: [seq_linter] .N:1 is likely to be wrong in the empty edge case. Use seq_len(1) instead.
# .N:1
# ^~~~

It also says seq_len(1) instead of seq_len(.N)

Activity

  1. added this to the 3.0.2 milestone on Sep 20, 2022
  2. IndrajeetPatil commented on Sep 20, 2022

    @IndrajeetPatil
    Collaborator

    The same issue also holds for all other relevant functions I think:

    library(lintr)
    
    lint(text = "length(x):1", linters = seq_linter())
    #> <text>:1:1: warning: [seq_linter] length(...):1 is likely to be wrong in the empty edge case. Use seq_along(...) instead.
    #> length(x):1
    #> ^~~~~~~~~~~
    
    length(BOD):1
    #> [1] 2 1
    
    rev(seq_along(BOD))
    #> [1] 2 1

    Created on 2022-09-20 with reprex v2.0.2

    We have a TODO to track this:

    lintr/R/seq_linter.R

    Lines 67 to 68 in a8d5d1f

    # TODO: better message customization. For example, length(x):1
    # would get rev(seq_along(x)) as the preferred replacement.

  3. MichaelChirico commented on Sep 20, 2022

    @MichaelChirico
    CollaboratorAuthor

    Also for viz: trying to get r-core to give me more confidence in recommending a replacement in the rev() case:

    https://bugs.r-project.org/show_bug.cgi?id=18406

  4. modified the milestones: 3.0.2, on Oct 12, 2022
  5. modified the milestones: , 3.2.0, 3.1.1 on Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions