Created
December 30, 2014 19:03
-
-
Save aousabdo/20977bc773043c1836e0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # start clean | |
| rm(list=ls()) | |
| # load libraries | |
| library(data.table) | |
| DT <- data.table(A = rnorm(10), B = rnorm(10)) | |
| # this gives lots of warnings, there seems to be a better way of doing this | |
| names(DT) <- tolower(names(DT)) | |
| # same with this line | |
| names(DT) <- gsub(" ", ".", names(DT)) |
Author
Author
updating data.table to dev version 1.9.5 fixes the problem.
The error message says that it's better to use setnames() instead of names<-. This was meant for older versions of R which copied the entire data.frame/data.table to just replace names. Improvements were made in Rv3.1+. But still the idiomatic way would be to use setnames().
HTH
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
R version 3.1.1 (2014-07-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
data.table 1.9.4
Warning:
Warning messages:
1: package ‘data.table’ was built under R version 3.1.2
2: In
names<-.data.table(*tmp*, value = c("a", "b")) :The names(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 names<- calls.
3: In
names<-.data.table(*tmp*, value = c("a", "b")) :The names(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 names<- calls.