[datatable-help] can I count on data.table supporting syntactically invalid column names?

Kaupas, George George.Kaupas at spansion.com
Tue Aug 7 23:39:42 CEST 2012


I'm taking advantage of a feature in data.table which lets me get away with naming columns with characters that would not survive a call to make.names(), e.g.:

> DT1 = data.table(a=letters[1:5], "Illegal(name%)"=1:5, key="a")
> DT1
   a Illegal(name%)
1: a              1
2: b              2
3: c              3
4: d              4
5: e              5

(The the dcast function from the reshape2 package will also create columns named "illegally".)

But when using merge.data.table, I get two side-effects; either the merge works, but the column names appear to be run through make.names(), or the merge fails in setcolorder():

> DT1 = data.table(a=letters[1:5], "Illegal(name%)"=1:5, key="a")
> DT2 = data.table(a=letters[1:5], b=6L, key="a")

> merge(DT1,DT2)
   a Illegal.name.. b
1: a              1 6
2: b              2 6
3: c              3 6
4: d              4 6
5: e              5 6

> merge(DT2,DT1)
Error in setcolorder(dt, c(setdiff(names(dt), end), end)) :
  neworder is length 4 but x has 3 columns.

I can't get to datatable.r-forge.r-project.org - getting a 504.

So... should I NOT rely on being able to use special characters in column names?

Thanks
George

> sessionInfo()
R version 2.15.0 (2012-03-30)
Platform: x86_64-unknown-linux-gnu (64-bit)
[1] data.table_1.8.2
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20120807/4846ab88/attachment.html>


More information about the datatable-help mailing list