[datatable-help] Random setnames() error although I don't even call this function.

Christoph Jäckel christoph.jaeckel at wi.tum.de
Tue Sep 11 22:35:32 CEST 2012


Hi together,

here's my code:

library(data.table)
test_fun <- function(DT, year) {

  adj_r2   <- DT[, list(Tau_1 = summary(lm(NI_1 ~
Total_Assets))$adj.r.squared,
                        Tau_2 = summary(lm(NI_2 ~
Total_Assets))$adj.r.squared)]


  adj_r2[, Year := as.integer(year)]

  adj_r2

}

DT <- data.table(NI_1 = rnorm(1000),
                 NI_2 = rnorm(1000),
                 Total_Assets = rnorm(1000))

test_fun(DT, 2000)

This gives me the following error on my windows machine:

Error in `[.data.table`(adj_r2, , `:=`(Year, as.integer(year))) :
  It appears that at some earlier point, names of this data.table have been
reassigned. Please ensure to use setnames() rather than names<- or
colnames<-. Otherwise, please report to datatable-help.

My sessionInfo():

R version 2.15.1 (2012-06-22)
Platform: x86_64-pc-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
 LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
 LC_TIME=German_Germany.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] data.table_1.8.2

loaded via a namespace (and not attached):
[1] tools_2.15.1

Interestingly, on my Linux machine, everything works fine:

Output there:
           Tau_1         Tau_2 Year
1: -0.0006947528 -0.0005516822 2000

sessionInfo()

R version 2.15.1 (2012-06-22)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
LC_MONETARY=en_US.UTF-8
 [6] LC_MESSAGES=en_US.UTF-8    LC_PAPER=C                 LC_NAME=C
           LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] iccFunctions_0.0.4 roxygen2_2.2.2     digest_0.5.2       dyn_0.2-8.1
     zoo_1.7-7          lubridate_1.1.0    data.table_1.8.2

loaded via a namespace (and not attached):
[1] brew_1.0-6      grid_2.15.1     lattice_0.20-10 plyr_1.7.1
 stringr_0.6.1   tools_2.15.1

Therefore, could someone with a Windows machine confirm this error?
Matthew, do you have an idea what is causing this?

Thanks in advance,

Christoph
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20120911/5e0f210f/attachment.html>


More information about the datatable-help mailing list