[Rcpp-devel] Problem with push_back to a list
Michael Hannon
jm_hannon at yahoo.com
Tue Oct 25 23:14:35 CEST 2011
[...]
> You were very, very close to this existing example from the unit test file
> runit.Vector.R (which, as Lists are GenericVector objects, also contains
> lists):
>
> ,"list_push_back"=list(
> signature(x = "list"),
> 'List list(x) ;
> list.push_back( 10 ) ;
> list.push_back( "bar", "foo" ) ;
> return list ;
> ')
>
> So with that it works if I write your example like this:
>
> -----------------------------------------------------------------------------
> library(inline)
>
> code <- '
> Rcpp::List myList(rList);
> myList.push_back(10);
> myList.push_back("foo", "bar");
> return myList;
> '
>
> lfun <- cxxfunction(signature(rList = "list"),
> body = code,
> plugin = "Rcpp")
> -----------------------------------------------------------------------------
>
> as can be seen below.
>
> Do not underestimate the usefulness of 750+ regression tests in 330+
> functions that are run with every release. They do provide examples, even if
> they are a little hard to read at first :)
>
> Also, if an example does not compile, comment-out and simplify til it
> does. The templated code is finicky. I often split very complex expression
> into components as there is no shame in using temporary variables....
Great! Thanks, Dirk. I HAVE looked at the runit stuff before but didn't
think to do so in this case.
-- Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20111025/6da2bd16/attachment.htm>
More information about the Rcpp-devel
mailing list