Skip to content

[Rcpp-devel] nested lists into Rcpp

2 messages · David García Callejas, Dirk Eddelbuettel

#
Hi all,

this is my first question here:

I have in R a list with several elements, some of them are lists, in the
vein of this:

mylist <- vector("list",10)
for(m in 1:10){
  mylist[[m]]$ID <- m
  mylist[[m]]$num <- vector("list",5)
  mylist[[m]]$num2 <- vector("list",5)
}

Is there a way to pass a data structure like this to a Rcpp function,
convert it to an appropriate C++ structure, and after doing some work with
it, return it in its original form?

fun <- cxxfunction(signature(x='List'), plugin='Rcpp', body = '
 using namespace std;
  List templist(x);
  //operations...
  return(wrap(templist));
   ')

Surely I am missing something obvious here, but I am just arrived to Rcpp,
and after looking in the documentation, I haven't found anything similar.
Thank you in advance
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130317/8bb9f6ed/attachment.html>
#
On 17 March 2013 at 21:36, David Garc?a Callejas wrote:
| Hi all,?
| 
| this is my first question here:
| 
| I have in R a list with several elements, some of them are lists, in the vein
| of this:
| 
| mylist <- vector("list",10)
| for(m in 1:10){
| ? mylist[[m]]$ID <- m
| ? mylist[[m]]$num <-?vector("list",5)
| ? mylist[[m]]$num2 <-?vector("list",5)
| }
| 
| Is there a way to pass a data structure like this to a Rcpp function, convert
| it to an appropriate C++ structure, and after doing some work with it, return
| it in its original form?
| 
| fun <- cxxfunction(signature(x='List'), plugin='Rcpp', body = ' ?
| ?using namespace std;
| ? List templist(x);
| ? //operations...
| ? return(wrap(templist));
| ? ?') ??
| 
| Surely I am missing something obvious here, but I am just arrived to Rcpp, and
| after looking in the documentation, I haven't found anything similar.?

There are working example in the RcppExamples packages -- and you need to
look at the C++ sources, obviously -- that do this.

Dirk

| Thank you in advance
| David
| 
| ----------------------------------------------------------------------
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel