<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">For whom it may concern, I wrote a (rather bulky) wrapper around rbindlist that:</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">- checks that the classes of columns with the same name match;</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">- fills in any missing columns with NAs of the appropriate type;</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">- reorders columns for consistency;</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">- calls rbindlist on the results of this preprocessing.</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><span style="font-family: Helvetica;"><br></span></div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><span style="font-family: Helvetica;">The code is here: </span>https://gist.github.com/asieira/7772953</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><span style="font-family: Helvetica;"><br></span></div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><span style="font-family: Helvetica;">The results would be as follows:</span></div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><span style="font-family: Helvetica;"><br></span></div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><div id="bloop_customfont" style="margin: 0px;">> smartrbindlist(list(data.table(a=1, b=2), data.table(b=4, a=3)))</div><div id="bloop_customfont" style="margin: 0px;"> a b</div><div id="bloop_customfont" style="margin: 0px;">1: 1 2</div><div id="bloop_customfont" style="margin: 0px;">2: 3 4</div><div id="bloop_customfont" style="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;">> smartrbindlist(list(data.table(a=1, b=2), list(c=3), data.table(d="foo")))</div><div id="bloop_customfont" style="margin: 0px;"> a b c d</div><div id="bloop_customfont" style="margin: 0px;">1: 1 2 NA NA</div><div id="bloop_customfont" style="margin: 0px;">2: NA NA 3 NA</div><div id="bloop_customfont" style="margin: 0px;">3: NA NA NA foo</div><div id="bloop_customfont" style="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;">> smartrbindlist(list(data.table(a=1L, b=2), list(a=10)))</div><div id="bloop_customfont" style="margin: 0px;">Erro em smartrbindlist(list(data.table(a = 1L, b = 2), list(a = 10)))</div><div id="bloop_customfont" style="margin: 0px;"> smartrbindlist: column a has different classes in entry 2 [numeric] and its predecessors [integer]</div><div id="bloop_customfont" style="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;">Hope this helps anyone else out there.</div></div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><span style="font-family: Helvetica;"><br></span></div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><span style="font-family: Helvetica;">-- </span></div><div id="bloop_sign_1386089364847001088"><div style="font-family: Helvetica; line-height: normal; "><span style="font-family: arial; font-size: small; ">Alexandre Sieira</span><br style="font-family: arial; font-size: small; "><span style="font-family: arial; font-size: small; ">CISA, CISSP, ISO 27001 Lead Auditor</span><br style="font-family: arial; font-size: small; "><br style="font-family: arial; font-size: small; "><span style="font-family: arial; font-size: small; ">"The truth is rarely pure and never simple."</span><br style="font-family: arial; font-size: small; "><span style="font-family: arial; font-size: small; ">Oscar Wilde, The Importance of Being Earnest, 1895, Act I</span></div></div> <br><p style="color:#A0A0A8;">On 3 de dezembro de 2013 at 14:46:08, G See (<a href="mailto://gsee000@gmail.com">gsee000@gmail.com</a>) wrote:</p> <blockquote type="cite" class="clean_bq"><span><div><div>I agree. Here is a related thread:
<br>http://thread.gmane.org/gmane.comp.lang.r.datatable/2231
<br>
<br>Garrett
<br>
<br>
<br>On Tue, Dec 3, 2013 at 8:26 AM, Alexandre Sieira
<br><alexandre.sieira@gmail.com> wrote:
<br>> I have come across some behavior in rbindlist that look unexpected to me:
<br>>
<br>>> rbindlist(list(data.table(a=1, b=2), data.table(b=4, a=3)))
<br>> a b
<br>> 1: 1 2
<br>> 2: 4 3
<br>>
<br>> So it appears to assume (without checking) that all objects have not only
<br>> the same column names but also the same column order. So a value assigned
<br>> to column ‘a’ in the second object was used for column ‘b’ in the end result
<br>> (and vice-versa).
<br>>
<br>> I know the documentation says rbindlist uses the column types from the first
<br>> entry of the list, but I didn’t see any mention to column order or names
<br>> anywhere.
<br>>
<br>> I suggest that column names are matched, even if they are not in the same
<br>> order. Perhaps a ‘use.names’ parameter could be used to ask for this
<br>> behavior to avoid breaking backwards compatibility.
<br>>
<br>> Or, at the very least, I suggest the documentation of bindlist be updated to
<br>> explicitly mention that the columns will be considered by position only, and
<br>> that callers need to ensure the column orders of all objects match exactly.
<br>> And that a warning is issued by rbindlist when the column names don’t match.
<br>>
<br>> --
<br>> Alexandre Sieira
<br>> CISA, CISSP, ISO 27001 Lead Auditor
<br>>
<br>> "The truth is rarely pure and never simple."
<br>> Oscar Wilde, The Importance of Being Earnest, 1895, Act I
<br>>
<br>> _______________________________________________
<br>> datatable-help mailing list
<br>> datatable-help@lists.r-forge.r-project.org
<br>> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
<br></div></div></span></blockquote></body></html>