Skip to content

fct_lump_n uses partial argument matching #276

Description

@Zedseayou

fct_lump_n uses partial argument matching when it calls rank, which generates a lot of warnings if you have options(warnPartialMatchArgs = TRUE) and repeatedly call the function (e.g. in a grouped operation).

library(forcats)
options(warnPartialMatchArgs = TRUE)
x <- c("a", "a", "a", "b", "b", "c", "d")
fct_lump_n(x, n = 2)
#> Warning in rank(-calcs$count, ties = ties.method): partial argument match of
#> 'ties' to 'ties.method'
#> [1] a     a     a     b     b     Other Other
#> Levels: a b Other

I think the culprit is here, with the named argument given as ties instead of ties.method.

forcats/R/lump.R

Lines 149 to 154 in ab81d1b

if (n < 0) {
rank <- rank(calcs$count, ties = ties.method)
n <- -n
} else {
rank <- rank(-calcs$count, ties = ties.method)
}

I haven't tried making the change but happy to PR if this would be welcome. I realise rank is unlikely to change signature but at least for me squelching the warnings would be great

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions