Thanks to visit codestin.com
Credit goes to github.com

Skip to content

unneeded_concatenation_linter() can throw on valid usages #1344

@MichaelChirico

Description

@MichaelChirico
lint("c(matrix(1:10, 2, 5))\n", unneeded_concatenation_linter())
# <text>:1:1: style: Unneeded concatenation of a constant. Remove the "c" call.
# c(matrix(1:10, 1, 5))
# ^~~~~~~~~~~~~~~~~~~~~

c() can be used as here to concisely drop the dimensions on a matrix, so we can't just throw a lint on all c(<expr>) cases.

We have considered whether this usage should always be replaced by a more declarative version like as.vector() instead; perhaps we could do so with a linter parameter. In any case, this new lint marks a departure from 2.0.1 behavior.

Note that the new behavior is good in some cases, e.g. it newly finds c(1 - alpha / 2) and c(1:10), but I'm not sure there's a maintainable way to always catch these.

Metadata

Metadata

Assignees

No one assigned

    Labels

    false-positivecode that shouldn't lint, but doesregressioncode that used to work, but now doesn't

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions