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

John Merrill john.merrill at gmail.com
Mon Nov 26 22:00:23 CET 2012


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


More information about the Rcpp-devel mailing list