Skip to content
Prev 2711 / 10988 Next

[Rcpp-devel] add new components to list without specifying list size initially

Ok, I started with smaller examples. I understand more or less how to
manipulate IntegerVectors, but not StringVectors (see below), and thus I
can't even start manipulating a simple list of StringVectors. Even so I
looked at mailing lists, StackOverflow, package pdf, source code on
R-Forge...

The following code tells me "warning: cannot pass objects of non-POD type
?struct Rcpp::internal::string_proxy<16>? through ?...?; call will abort at
runtime": why does it complain about printing the string in vec_s[i]?

fn <- cxxfunction(signature(l_in="list"),
                  body='
using namespace Rcpp;
List l = List(l_in);
Rprintf("list size: %d\\n", l.size());

IntegerVector vec_i= IntegerVector(2);
vec_i[0] = 1;
vec_i[1] = 2;
List l2 = List::create(_["vec"] = vec_i);
Rprintf("vec_i size: %d\\n", vec_i.size());
for(int i=0; i<vec_i.size(); ++i)
  Rprintf("vec_i[%d]=%d\\n", i, vec_i[i]);

StringVector vec_s = StringVector::create("toto");
vec_s[0] = "toto";
Rprintf("vec_s size: %d\\n", vec_s.size());
for(int i=0; i<vec_s.size(); ++i)
  Rprintf("vec_s[%d]=%s\\n", i, vec_s[i]);

return l2;
',
                  plugin="Rcpp", verbose=TRUE)
print(fn(list(a=c(1,2,3), b=c("a","b","c"))))

Moreover, how can I access the component of a list given as input, as "l_in"
above? Should I use l.begin()? or l[1]? or l["a"]? none of them seems to
compile successfully.
On Thu, Aug 11, 2011 at 8:54 PM, Dirk Eddelbuettel <edd at debian.org> wrote:

            
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20110812/7e39f407/attachment-0001.htm>