<div dir="ltr">Thank you for all the responses Dirk.<div>I will go through them one at a time to see what I can accomplish on my own.</div><div>Further questions will follow in the next few weeks (I imagine).</div><div><br>

</div><div>Cheers,</div><div>Tal</div><div><br></div></div><div class="gmail_extra"><br clear="all"><div><div dir="ltr"><br>----------------Contact Details:-------------------------------------------------------<br>Contact me: <a href="mailto:Tal.Galili@gmail.com" target="_blank">Tal.Galili@gmail.com</a> |  <br>

Read me: <a href="http://www.talgalili.com" target="_blank">www.talgalili.com</a> (Hebrew) | <a href="http://www.biostatistics.co.il" target="_blank">www.biostatistics.co.il</a> (Hebrew) | <a href="http://www.r-statistics.com" target="_blank">www.r-statistics.com</a> (English)<br>

----------------------------------------------------------------------------------------------<br><br></div></div>
<br><br><div class="gmail_quote">On Sat, Jul 20, 2013 at 11:31 PM, Dirk Eddelbuettel <span dir="ltr"><<a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<br>
Hi Tal,<br>
<div class="im"><br>
On 20 July 2013 at 22:14, Tal Galili wrote:<br>
| Hello Dirk and others,<br>
|<br>
| Dirk - <br>
| Thank you for the quick reply!<br>
|<br>
| Some responses:<br>
|<br>
|<br>
| 1) I looked at the Rcpp gallery.<br>
| The best I found was:<br>
| <a href="http://gallery.rcpp.org/articles/setting-object-attributes/" target="_blank">http://gallery.rcpp.org/articles/setting-object-attributes/</a><br>
| (which already was available in Hadley's book)<br>
<br>
</div>Sure. He too recycled some older posts. What goes around ...<br>
<div class="im"><br>
| And:<br>
| <a href="http://gallery.rcpp.org/articles/modifying-a-data-frame/" target="_blank">http://gallery.rcpp.org/articles/modifying-a-data-frame/</a><br>
| <a href="http://gallery.rcpp.org/articles/reversing-a-vector/" target="_blank">http://gallery.rcpp.org/articles/reversing-a-vector/</a><br>
|<br>
| And also now at unitTests/cpp/DataFrame<br>
| (interesting)<br>
|<br>
| But none have helped me with getting the attributes of an element inside a<br>
| List.<br>
| That is, say that we have x as a List, how do we go about fetching its attr?<br>
| I tried:<br>
| x[1].attr("type")<br>
| x.attr[1]("type")<br>
| But none seemed to have worked. Any suggestions there?<br>
<br>
</div>Sometimes it is easier / better / necessary to do this in two steps.<br>
<br>
First some R data:<br>
<br>
R> foo <- list(bar=42, bing=21)<br>
R> attr(foo[[1]], "type") <- "xyz"<br>
<br>
Then a quick function in C++:<br>
<br>
R> cppFunction('CharacterVector tal(List x) { IntegerVector y = x[0]; return y.attr("type"); }')<br>
R> tal(foo)<br>
[1] "xyz"<br>
R><br>
<br>
So once I take the element out of the list and assign it to a "standalone"<br>
variable, things work.  [ This protects against overzealous template<br>
expansions. ]<br>
<br>
Similarly, I don't think you can (yet) easily do the attr() call on a sublist<br>
in a list.<br>
<div class="im"><br>
| 2) Your book is on my "to get a hold of somehow" list. Getting books to Israel<br>
| is always trickier - I might just get it when I'll visit the US in a few<br>
| months.<br>
<br>
</div>I see.<br>
<div class="im"><br>
| 3) The post on Rcpp didn't get on R-bloggers since it wasn't marked with the<br>
| "R" category.<br>
| <a href="http://blog.revolutionanalytics.com/2013/07/" target="_blank">http://blog.revolutionanalytics.com/2013/07/</a><br>
| deepen-your-r-experience-with-rcpp.html<br>
| (David could still fix it if he wants to - and set the date of the post to be<br>
| more recent)<br>
<br>
</div>I see. Could you email Joe (or David) ?<br>
<div class="im"><br>
| 4) Having an<br>
| is<List>(x) will be nice. Although I will need to see some examples to see when<br>
| it is better then simply using: <br>
| x.inherits("list")<br>
|<br>
| 5) I couldn't find a<br>
|  'dispatch on type' example in the Rcpp gallery.<br>
| I'm probably missing something in how I'm searching there.<br>
<br>
</div>Sorry, I was thinking of<br>
<br>
   <a href="http://gallery.rcpp.org/articles/rcpp-wrap-and-recurse/" target="_blank">http://gallery.rcpp.org/articles/rcpp-wrap-and-recurse/</a><br>
<br>
which uses TYPEOF() and ...SXP to match on type.<br>
<div class="im"><br>
| 6) Environment.cpp in the unitTest is interesting. It is probably what I<br>
| needed.<br>
<br>
</div>Yes!<br>
<div class="im"><br>
| 7) To Dirk and others - I will be happy to wait a bit to see if any of you can<br>
| help by writing the R functions from my previous e-mail in Rcpp. That would be<br>
| a big help for me in understanding how the relevant pieces should fit together.<br>
| (the functions themselves are not useful, but they require many of the features<br>
| I imagine I will need later on).<br>
<br>
</div>Maybe start with something simpler.  Just recursing through a list and<br>
printing the (integer or whatever) elements is a very good exercise.<br>
<div class="HOEnZb"><div class="h5"><br>
Cheers, Dirk<br>
<br>
--<br>
Dirk Eddelbuettel | <a href="mailto:edd@debian.org">edd@debian.org</a> | <a href="http://dirk.eddelbuettel.com" target="_blank">http://dirk.eddelbuettel.com</a><br>
</div></div></blockquote></div><br></div>