[Rcpp-devel] trouble creating a dataframe
Pratibha Rana
pratibha.r.tomar at gmail.com
Mon Jun 4 22:12:39 CEST 2012
Hi,
I am at my wits end trying to create a dataframe from a list of values
that I have. here's the code
try{
int size = argTypes.getColumnCount();
std::vector<std::string> nameVec(size);
std::vector<int> lenVec(size);
std::vector<int> scaleVec(size);
for (size_t i = 0; i < size; ++i) {
//get the datatype
vt = argTypes.getColumnType(i);
BaseDataOID BDOid = vt.getTypeOid();
//convert the Oid to string name
std::string columnType = Oid2String(BDOid);
//get the length for string types, precision for time and
numerics and scale for numerics
int length = 0;
int scale= 0;
getTypeLength(vt, length, scale);
//add the values to the vectors
nameVec.push_back(columnType);
lenVec.push_back(length);
scaleVec.push_back(scale);
}
//create the dataframe
Rcpp::List df = Rcpp::List::create(Rcpp::Named("datatype",nameVec),
Rcpp::Named("length",lenVec),
Rcpp::Named("scale",scaleVec));
Rcpp::DataFrame df_final = Rcpp::DataFrame::create(df);
return df_final;
}
catch(std::exception &e) {
throw;
}
The std::vectors are created fine but the list is not created
(gdb) p R_PV(df)
$3 = 0
I have tried a lot of variation like creating the dataframe directly
without first creating the list. Nothing seems to be working.
Thanks
Pratibha
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20120604/b7a86665/attachment.html>
More information about the Rcpp-devel
mailing list