[Rcpp-devel] Dynamically creating data.frame/list (of vectors)

Robert A'gata rhelpacc at gmail.com
Thu Nov 29 04:05:19 CET 2012


Hi all,

Thank you so much for your valuable input. I can definitely store list of
columns and keeps appending to the table using STL list. But my question is
that what kind of abstraction for each column type I should use? In STL
list, But that will mean I have to be able to construct STL list with
dynamic type depending on the columns in my returning query. Can I make all
of the columns into, says, list<SEXP> for abstraction purpose? Then just
cast it into corresponding type when creating data.frame to return back to
R? Any snippet to demonstrate the idea would be appreciated. Thank you!


On Mon, Nov 26, 2012 at 4:00 PM, John Merrill <john.merrill at gmail.com>wrote:

> There's a small issue with that -- if your columns contain any
> character lists, then those columns wind up being coerced into factors
> by as.data.frame (inside the constructor).  You can work around that
> by either setting the default value of the stringsAsFactors option to
> FALSE, and then resetting it after you create the data frame, or by
> setting the "AsIs" class attribute on the column and then removing it
> after you create the dataframe.  Neither of these is pretty, but they
> both work.
>
> On Mon, Nov 26, 2012 at 12:55 PM, Dirk Eddelbuettel <edd at debian.org>
> wrote:
> >
> > On 26 November 2012 at 12:41, Davor Cubranic wrote:
> > | On 2012-11-23, at 1:36 PM, Robert A'gata wrote:
> > |
> > | > Inside onEventA, I'd like to be able to create a blank data.frame or
> > | > list with zero length vector. Once my data frame or list object is
> > | > constructed, I'd like to append a new row to it each time onEventB is
> > | > invoked. How can I achieve this in Rcpp? Thank you.
> > |
> > | Can you possibly stay in STL and keep rows in std::list, and only
> construct a Rcpp::DataFrame before you return to R?
> >
> > Seconded -- meant to reply as well and got side-tracked.
> >
> > That's why I once did to gather data from a tick data plant. I just grew
> > everything (on callbacks from the ticker database system) in a stateful
> C++
> > class, and then transformed into Rcpp types before returning the query
> to R.
> >
> > I knew how many columns I'd get at the beginning of the result set, and
> could
> > then grew them as results came in.  Was a nice solution and better than
> what
> > the vendor offered via ODBC :)
> >
> > Dirk
> >
> > --
> > Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
> > _______________________________________________
> > Rcpp-devel mailing list
> > Rcpp-devel at lists.r-forge.r-project.org
> > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20121128/c51acd8d/attachment.html>


More information about the Rcpp-devel mailing list