You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
setnames could break out early if identical(old,new) #3783
This case is a nice one. Have been looking at it and @HughParsonage seems right to me: that case (where the pattern is not matched to any column name) does not overwrite the names redundantly. Even where only a few column names are matched, it only updates those. So if those don't touch key or index names, then the key or index name updates will be saved too. The setnames(DT, new) form seems fine then and no improvement possible.
The PR nicely improves the other form (setnames(DT, old, new)) which wasn't doing any of the redundancy checking or saving.
Activity
MichaelChirico commentedon Aug 20, 2019
Actually it already does this in the
missing(new)casedata.table/R/data.table.R
Lines 2447 to 2451 in a8e926a
Will file a fix for
!missing(new)Closes #3783 -- setnames exits early when theres nothing to do
HughParsonage commentedon Aug 27, 2019
I believe this would work already, no? If the pattern in
gsubis not matched the replacement is not attempted.MichaelChirico commentedon Aug 27, 2019
@HughParsonage it works but setnames still overwrites the names redundantly
mattdowle commentedon Aug 30, 2019
This case is a nice one. Have been looking at it and @HughParsonage seems right to me: that case (where the pattern is not matched to any column name) does not overwrite the names redundantly. Even where only a few column names are matched, it only updates those. So if those don't touch key or index names, then the key or index name updates will be saved too. The
setnames(DT, new)form seems fine then and no improvement possible.The PR nicely improves the other form (
setnames(DT, old, new)) which wasn't doing any of the redundancy checking or saving.