Perhaps a stupid question, but I searched a lot for the answer and could not find it:
I am trying to write a la freador file reader read.delim, but is implemented in C ++ and connected to R via Rcpp. The easiest way to do this and make it output data.frame is to create Listvectors - one for each column - and set the class todata.frame
List foo;
foo.push_back(column);
foo.attr("class") = "data.frame";
return foo;
Simple enough, and I've done it before. Unfortunately:
- The file (s) I want to read may have a different number of fields;
- This model only works elegantly if you are reading from a file column, while actual files tend to be read differently.
So the answer should be able to define foo, and then for every line I read, a push_back () field for each of the base vectors foo:
List foo(1);
foo[0].push_back("turnip");
Unfortunately, I cannot figure out how to do this: it does not seem that the List member vectors can be pushed_back (), as this leads to the error "Rcpp :: Vector <19> :: Proxy has no member named push_back ( ) "
So my question is: is there a way to add Rcpp to the vector in the list? Or is my only option for reading a file column by column, adding the resulting vectors to "foo" and biting the cost of performance that would arise because it would go through it [number of columns] times, not once?
Hope this question is clear enough. Glad to answer any questions.