<div dir="ltr">I agree that this is not a complete implementation; it isn't meant to be, although it might still be a worth incorporating this into Rcpp with the appropriate fixes in place. <div><br></div><div>For instance, the vector recycling issue is far from the greatest limitation of this code: it handles character vectors wrong, The R routine converts character vectors into factors unless overridden; I wrote the precursor of this particular routine because I wanted to handle strings faithfully, and so writing a stupid R routine to coerce lists of lists of constant length to data frames.</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Jan 31, 2013 at 3:21 AM, Romain Francois <span dir="ltr"><<a href="mailto:romain@r-enthusiasts.com" target="_blank">romain@r-enthusiasts.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Le 15/01/13 16:20, John Merrill a écrit :<div><div class="h5"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
It appears that DataFrame::create is a thin layer on top of the R<br>
data.frame call. The guarantee correctness, but also means the<br>
performance of an Rcpp routine which returns a large data frame is<br>
limited by the performance of data.frame -- which is utterly horrible.<br>
<br>
In the current version of R, there's a trivial, but borderline evil,<br>
work around: build a list of lists meeting the basic requirements of a<br>
data frame (they all need to be of the same length, and each component<br>
list needs to be named) and set the type of the object to "data.frame".<br>
<br>
I have two questions:<br>
(1) Is it reasonable to anticipate that this hack will continue to work<br>
for the near future in R?<br>
(2) If so, would a patch to that effect be of interest to the developers?<br>
</blockquote>
<br></div></div>
The reason we used a callback to data.frame is close to lazyness on our part. With the R function, for example we know that columns of different sizes will be handled properly, with recylcling, etc ...<br>
<br>
Just making a named list of vectors is not enough. We have to make sure they all have the same length.<br>
<br>
Perhaps it would be worth checking this and make better DataFrame::create functions.<br>
<br>
<br>
<br>
Also, you can use a shortcut to assign row names, i.e. mimic this in C++ (the second line contains the magic):<br>
<br>
> d <- list( x = 1:10, y = 1:10 )<br>
> attr( d, "row.names" ) <- c( NA, -10L )<br>
> attr( d, "class" ) <- "data.frame"<br>
> d<br>
x y<br>
1 1 1<br>
2 2 2<br>
3 3 3<br>
4 4 4<br>
5 5 5<br>
6 6 6<br>
7 7 7<br>
8 8 8<br>
9 9 9<br>
10 10 10<span class="HOEnZb"><font color="#888888"><br>
<br>
<br>
Romain<br>
<br>
-- <br>
Romain Francois<br>
Professional R Enthusiast<br>
<a href="tel:%2B33%280%29%206%2028%2091%2030%2030" value="+33628913030" target="_blank">+33(0) 6 28 91 30 30</a><br>
<br>
R Graph Gallery: <a href="http://gallery.r-enthusiasts.com" target="_blank">http://gallery.r-enthusiasts.<u></u>com</a><br>
<br>
blog: <a href="http://romainfrancois.blog.free.fr" target="_blank">http://romainfrancois.blog.<u></u>free.fr</a><br>
|- <a href="http://bit.ly/RE6sYH" target="_blank">http://bit.ly/RE6sYH</a> : OOP with Rcpp modules<br>
`- <a href="http://bit.ly/Thw7IK" target="_blank">http://bit.ly/Thw7IK</a> : Rcpp modules more flexible<br>
<br>
</font></span></blockquote></div><br></div>