Skip to content

setnames() accepts function for old= and new=#3860

Merged
mattdowle merged 6 commits intomasterfrom
fix3703
Sep 12, 2019
Merged

setnames() accepts function for old= and new=#3860
mattdowle merged 6 commits intomasterfrom
fix3703

Conversation

@shrektan
Copy link
Copy Markdown
Member

Closes #3703

library(data.table)
DT = data.table(a=1:3, b=4:6, c=7:9)
setnames(DT, base::toupper)
names(DT)
#> [1] "A" "B" "C"
setnames(DT, c('B','C'), function(x) sprintf('W_%s_W', x))
names(DT)
#> [1] "A"     "W_B_W" "W_C_W"
DT = data.table(a=1:3, b=4:6, c=7:9)
# support numeric old as well
setnames(DT, 1, toupper)
names(DT)
#> [1] "A" "b" "c"
setnames(DT, -1, toupper)
names(DT)
#> [1] "A" "B" "C"

Created on 2019-09-12 by the reprex package (v0.3.0)

Merge branch 'master' of github.com:Rdatatable/data.table into fix3703

# Conflicts:
#	inst/tests/tests.Rraw
@codecov
Copy link
Copy Markdown

codecov bot commented Sep 11, 2019

Codecov Report

Merging #3860 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3860      +/-   ##
==========================================
+ Coverage   99.42%   99.42%   +<.01%     
==========================================
  Files          71       71              
  Lines       13423    13425       +2     
==========================================
+ Hits        13346    13348       +2     
  Misses         77       77
Impacted Files Coverage Δ
R/data.table.R 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 460b91b...e945934. Read the comment docs.

@jangorecki jangorecki added this to the 1.13.0 milestone Sep 11, 2019
@mattdowle mattdowle changed the title Closes #3703: setnames() accepts function for old= and new= setnames() accepts function for old= and new= Sep 11, 2019
@mattdowle mattdowle modified the milestones: 1.13.0, 1.12.4 Sep 11, 2019
@mattdowle mattdowle merged commit b017347 into master Sep 12, 2019
@mattdowle mattdowle deleted the fix3703 branch September 12, 2019 00:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow functions in setnames input

3 participants