Steve and Dirk, thanks again, I will look into the GenomicRanges package
for my immediate usage, but for my future need, I will also keep trying
to manipulate nested lists with Rcpp, as all my data structures are as
such.<br><br><div class="gmail_quote">On Fri, Aug 12, 2011 at 4:37 PM, Dirk Eddelbuettel <span dir="ltr"><<a href="mailto:edd@debian.org">edd@debian.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div><div></div><div class="h5"><br>
On 12 August 2011 at 16:26, Walrus Foolhill wrote:<br>
| Thanks for your advice, I now understand how to manipulate one-level lists:<br>
|<br>
| fn <- cxxfunction(signature(l_in="list"),<br>
| Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â body='<br>
| using namespace Rcpp;<br>
| List l(l_in);<br>
| IntegerVector lf = l["foo"];<br>
| CharacterVector lb = l["bar"];<br>
| for(int i=0; i<lf.size(); ++i)<br>
| Â Rprintf("l[%s][%i] %i\\n", "foo", i, lf[i]);<br>
| for(int i=0; i<lb.size(); ++i)<br>
| Â Rprintf("l[%s][%i] %s\\n", "bar", i, std::string(lb[i]).c_str());<br>
| ', plugin="Rcpp", verbose=TRUE)<br>
| z <- fn(list(foo=c(1,2,3,4),bar=c("bar1","bar2")))<br>
|<br>
| But what about 2-level lists? Why the following code doesn't compile?<br>
|<br>
| fn <- cxxfunction(signature(l_in="list"),<br>
| Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â body='<br>
| using namespace Rcpp;<br>
| List l(l_in);<br>
| List lf(l["foo"]);<br>
| ', plugin="Rcpp", verbose=TRUE)<br>
| z <- fn(list(foo=list(bar=1)))<br>
|<br>
| And what the following message mean? "error: call of overloaded ‘Vector<br>
| (Rcpp::internal::generic_name_proxy<19>)’ is ambiguous"<br>
|<br>
| I had a look at "runit.Vector.R" on r-forge, but couldn't find any test<br>
| involving 2-level (or more) lists, although on SO in June 2010 (http://<br>
| <a href="http://stackoverflow.com/questions/3088650/how-do-i-create-a-list-of-vectors-in-rcpp/" target="_blank">stackoverflow.com/questions/3088650/how-do-i-create-a-list-of-vectors-in-rcpp/</a><br>
| 3088744#3088744), you said that it should work.<br>
|<br>
| I checked that I can create a 2-level list, but the code below doesn't compile<br>
| if I uncomment the last Rprintf line:<br>
<br>
</div></div>There can be times when the C++ templating gets in the way, so if this<br>
doesn't work in a single statement, decompose it into two (one to assign to a<br>
temp, another to print them temp) and move on.<br>
<br>
I have done two-level lists in the past; one key is that a list ... is just<br>
another SEXP, or can be wrap()'ed to a SEXP, and you can hence assign a list<br>
to be a component of another. And then another and so on...<br>
<font color="#888888"><br>
Dirk<br>
</font><div><div></div><div class="h5"><br></div></div></blockquote></div>