<div dir="ltr">I took a cursory look at your code - the new rbind does everything you want (check use.names and the fill arguments), and you may want to take a look at its code.</div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Tue, Dec 3, 2013 at 11:05 AM, Alexandre Sieira <span dir="ltr"><<a href="mailto:alexandre.sieira@gmail.com" target="_blank">alexandre.sieira@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word"><div 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 style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><br></div><div 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 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 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 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 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 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><a href="https://gist.github.com/asieira/7772953" target="_blank">https://gist.github.com/asieira/7772953</a></div><div 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 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 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 style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto">
<div style="margin:0px">> smartrbindlist(list(data.table(a=1, b=2), data.table(b=4, a=3)))</div><div class="im"><div style="margin:0px"> a b</div><div style="margin:0px">1: 1 2</div></div><div style="margin:0px">2: 3 4</div>
<div style="margin:0px"><br></div><div style="margin:0px">> smartrbindlist(list(data.table(a=1, b=2), list(c=3), data.table(d="foo")))</div><div style="margin:0px"> a b c d</div><div style="margin:0px">
1: 1 2 NA NA</div><div style="margin:0px">2: NA NA 3 NA</div><div style="margin:0px">3: NA NA NA foo</div><div style="margin:0px"><br></div><div style="margin:0px">> smartrbindlist(list(data.table(a=1L, b=2), list(a=10)))</div>
<div style="margin:0px">Erro em smartrbindlist(list(data.table(a = 1L, b = 2), list(a = 10)))</div><div style="margin:0px"> smartrbindlist: column a has different classes in entry 2 [numeric] and its predecessors [integer]</div>
<div style="margin:0px"><br></div><div style="margin:0px">Hope this helps anyone else out there.</div></div><div class="im"><div 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 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><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></div><div><div class="h5"><p style="color:#a0a0a8">On 3 de dezembro de 2013 at 14:46:08, G See (<a href="mailto://gsee000@gmail.com" target="_blank">gsee000@gmail.com</a>) wrote:</p> <blockquote type="cite"><span><div>
<div>I agree. Here is a related thread:
<br><a href="http://thread.gmane.org/gmane.comp.lang.r.datatable/2231" target="_blank">http://thread.gmane.org/gmane.comp.lang.r.datatable/2231</a>
<br>
<br>Garrett
<br>
<br>
<br>On Tue, Dec 3, 2013 at 8:26 AM, Alexandre Sieira
<br><<a href="mailto:alexandre.sieira@gmail.com" target="_blank">alexandre.sieira@gmail.com</a>> 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>> <a href="mailto:datatable-help@lists.r-forge.r-project.org" target="_blank">datatable-help@lists.r-forge.r-project.org</a>
<br>> <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help</a>
<br></div></div></span></blockquote></div></div></div><br>_______________________________________________<br>
datatable-help mailing list<br>
<a href="mailto:datatable-help@lists.r-forge.r-project.org">datatable-help@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help</a><br></blockquote></div><br></div>