<div>When I try to rbind an empty data.table to a non-empty data table, all my data are converted to logical. Here's an example</div><div><br></div><div># create a directory and put 2 csv file in it.</div><div>dir.create("~/tmp")</div>
<div>system("echo 'A,B' > ~/tmp/new.csv") # this csv only has headers; no data</div><div>write.csv(data.frame(A=1, B=2), row.names=FALSE, file='~/tmp/new2.csv') # this one has header and 1 row</div>
<div><br></div><div>lapply(c("~/tmp/new.csv", "~/tmp/new2.csv"), read.csv)</div><div>#[[1]]</div><div>#[1] A B</div><div>#<0 rows> (or 0-length row.names)</div><div>#</div><div>#[[2]]</div><div># A B</div>
<div>#1 1 2</div><div><br></div><div># now rbind them, and we're left with the data from the non-empy csv</div><div>do.call(rbind, lapply(c("~/tmp/new.csv", "~/tmp/new2.csv"), read.csv))</div><div>
# A B</div><div>#1 1 2</div><div><br></div><div># Now let's try to work with data.tables instead of data.frames</div><div>lapply(c("~/tmp/new.csv", "~/tmp/new2.csv"), function(x) as.data.table(read.csv(x)))</div>
<div>#[[1]]</div><div>#Empty data.table (0 rows) of 2 cols: A,B</div><div>#</div><div>#[[2]]</div><div># A B</div><div>#1: 1 2</div><div><br></div><div>#Ok, but look at what happens when we rbind them</div><div>do.call(rbind, lapply(c("~/tmp/new.csv", "~/tmp/new2.csv"), function(x) as.data.table(read.csv(x))))</div>
<div> A B</div><div>1: TRUE TRUE</div><div><br></div><div><br></div><div> What's going on here?<br></div><div><br></div><div>Thanks,</div><div>Garrett</div>