Skip to content

Spurious snake_case error when using $ in assignment #582

Closed

Description

@nsoranzo
get_deseq_dataset.R:60:17: style: Variable and function name style should be snake_case.
        tx2gene$TXNAME <- sub("^transcript:", "", tx2gene$TXNAME)
                ^~~~~~

Activity

  1. russHyde commented on Nov 24, 2020

    @russHyde
    Collaborator

    Since TXNAME is all caps, rather than in snake_case, the linter seems to be functioning correctly here.

  2. nsoranzo commented on Nov 24, 2020

    @nsoranzo
    Author

    @russHyde TXNAME is not the variable name though, tx2gene is. TXNAME is used with the $ operator to subset a data.frame column by name, it is equivalent to tx2gene[["TXNAME"]] , which lints fine.
    Column names are often coming from third-party libraries, so I'd suggest to lint only the variable name (i.e. stop at the $).

  3. russHyde commented on Nov 24, 2020

    @russHyde
    Collaborator

    Sorry, I hope it didn't sound glib. It's a difficult call whether subelements of a list/data.frame are variables, since they define variables that are nested in an environment defined by the top-level variable.

    It might need quite a bit of thought to make lintr distinguish linting when i) assigning to top-level variables from ii) assigning to their subelements.

    If it were possible, and accepting that there are some people who would want the subelement names to be linted by object_name_linter how should the linter API work?

    # ? something like this ?
    my_linter <- object_name_linter(case = "snake_case", lint_subelements = FALSE)
    lint(my_file, linters = list(snake_case_linter = my_linter))
    

    It's a bit verbose but could be thought about.

  4. added a commit that references this issue on Nov 24, 2020
  5. added
    bug
    on Dec 9, 2020
  6. AshesITR commented on Feb 15, 2021

    @AshesITR
    Collaborator

    #759 contains the XPath necessary to disambiguate symbols used in OP-DOLLAR contexts vs. as variable names.

  7. added 2 commits that reference this issue on Feb 18, 2021
    46d2087
    3d0fc88
  8. added this to the 3.0.0 milestone on Feb 18, 2021
  9. added a commit that references this issue on Feb 27, 2021
    59810b5
  10. added a commit that references this issue on Aug 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions