Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore safety check when using setnames

Tags:

r

data.table

DT<-data.table(a=1,b=2,a=3)
DT
#   a b a
#1: 1 2 3
setnames(DT,"b","c")
#Error in setnames(DT, "b", "c") : 
# 'old' is character but there are duplicate column names: a

In the example above, you can see that I wish to change the header of a column that is not duplicated, but setnames prevents me from doing so. Is there a way to ignore the check, as the column header I am changing is not duplicated?

like image 285
Wet Feet Avatar asked Jan 06 '14 04:01

Wet Feet


1 Answers

+1 Now fixed in v1.8.11. From NEWS :

setnames(DT,"oldname","newname") no longer complains about duplicated column names in DT so long as oldname is unique and unambiguous. Thanks to Wet Feet for highlighting.

like image 161
Matt Dowle Avatar answered Sep 23 '22 01:09

Matt Dowle