Rの<-はAPLの名残り

ひとりアドベントカレンダー7日目。
data.table型に対してcolnamesなどを適用すると下のような警告が出る。

> library("data.table")
> smp <- as.data.table(iris)
> colnames(smp) <- colnames(smp)
 警告メッセージ: 
In `names<-.data.table`(`*tmp*`, value = value) :
  The colnames(x)<-value syntax copies the whole table. This is due to <- in R itself. Please change to setnames(x,old,new) which does not copy and is faster. See help('setnames'). You can safely ignore this warning if it is inconvenient to change right now. Setting options(warn=2) turns this warning into an error, so you can then use traceback() to find and change your colnames<- calls.

colnames(hoge) <- なんたら、とするとテーブルをまるまるコピーしてしまうなどという恐ろしいことが書いてある。
?setnamesとしてヘルプをみると以下のような文章がある。

The <- method copies the whole table and we know of no way to avoid that copy without a change in R itself. Please use the set* functions instead, which make no copy at all.

この辺の挙動について知りたい人はAdvanced Rのreplacement functionの項を読むと良い。
一応邦訳も出る。

R言語徹底解説

R言語徹底解説

が、既に日本語で解説もある。さっと知りたい人はこちらお勧め。
http://notchained.hatenablog.com/entry/2014/01/08/235901

ちなみに<-(アロー演算子)はAPLの名残だそうな。
http://blog.revolutionanalytics.com/2008/12/use-equals-or-arrow-for-assignment.html
APLが何か分からない人は以下のJapan.Rの資料をご覧いただきたい。
http://www.slideshare.net/yatsuta/apl-for-rusers