Skip to content

setnames could break out early if identical(old,new) #3783

@MichaelChirico

Description

@MichaelChirico

Am writing a function that works like

if (length(idx <- grep('^_', names(x)))) setnames(x, idx, gsub('^_', '', names(x)[idx])

It would be cleaner to just write

setnames(x, gsub('^_', '', names(x)))

And (in the !length case) let setnames realize old and new are the same & return early for efficiency.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions