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.
Am writing a function that works like
It would be cleaner to just write
And (in the
!lengthcase) letsetnamesrealizeoldandneware the same & return early for efficiency.