Skip to content

New linter: discourage the use of anonymous functions for trivial cases #1531

Description

@Bisaloo

Example

Discouraged

lapply(l, function(x) mean(x)))

Recommended

lapply(l, mean)

Scope

  • to limit the risk of false positive, I'm thinking to limit this to the apply() family function (+ replicate()), at least as a first step. Or do you think it wouldn't be much more difficult and riskier to do this in all contexts?

  • ideally, this should detect also both tidyverse (~ mean(.x)) and base (\(x) mean(x)) lambda functions

  • I'm thinking to limit it to cases with a single argument, i.e. exclude:

    lapply(l, function(x) mean(x, na.rm = TRUE))

    even though the anonymous function could be removed here as well by forwarding the ... because users might find it clearer to not forward them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions