I followed this link
Passing a data frame from-to R and C using .call()
to find the way to access an R data frame inside C. My requirement is the opposite of that. I have a tabular data in C and need to create an R data frame object in C and return it on as SEXP.
For simple R vectors and lists creation, I followed something like in this link
http://adv-r.had.co.nz/C-interface.html
But I am still wondering how to create a dataframe and return from C to R. Considering a dataframe is a list, I tried creating a list and passing it on, but it expectedly gets me a list in R and not a dataframe.
Any help would be appreciated.
Obligatory Rcpp example:
// [[Rcpp::export]]
DataFrame createTwo(){
IntegerVector v = IntegerVector::create(1,2,3);
std::vector<std::string> s(3);
s[0] = "a";
s[1] = "b";
s[2] = "c";
return DataFrame::create(Named("a")=v, Named("b")=s);
}
which will get you a 3x2 data.frame with one char vector and one int vector.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With