Skip to content
Prev 5592 / 10988 Next

[Rcpp-devel] DataFrame and passing by reference

Thanks Kevin,
This question came because when you do this

// [[Rcpp::export]]
DataFrame updateDFByValue(DataFrame df) {
    int N = df.nrows();
    NumericVector newCol(N,1.);
    df["newCol"] = newCol;
    return(df);
}

The DataFrame is returned to R as a list, and building back another
data.frame might

   1. cost time
   2. appear like a waste if what was intended was to update the data.frame

<http://cran.r-project.org/web/packages/data.table/index.html>
data.tableallows by-reference updates in R but there is no C api that
I know of, but
it is an enhanced data.frame so Rcpp deals with it as a data.frame, I
thought it was too bad to be able to update by reference in R and not in
C++ so I asked this genuine question.

Your way makes sense to me, I'll try to dig deeper.
Thanks

PS: Dirk answered me
here<http://stackoverflow.com/questions/15731106/passing-by-reference-a-data-frame-and-updating-it-with-rcpp>

2013/3/31 Kevin Ushey <kevinushey at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130331/972a90c0/attachment.html>