<div dir="ltr">Hi Tal,<div><br></div><div>In your example, note that x[[1]] is not a list; hence it must first be coerced to a list, and attributes are lost in this conversion. This is fairly standard in R code; eg x <- 1; attr(x, "animal") <- "cat"; x; as.list(x), so you can't blame Rcpp for being consistent with R here.</div>

<div><br></div><div>The onus is on you to be careful with your types when setting attributes. You should assume they are lost if you do any conversion. Indeed, the non-standard attributes are very brittle.</div><div><br>
</div>
<div>That said, if you want the size of an RObject, there is always the C API to fall back on: Rf_length(x) gives you the length of the object, agnostic to its type.</div><div><br></div><div>-Kevin</div></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Tue, Aug 20, 2013 at 2:31 PM, Tal Galili <span dir="ltr"><<a href="mailto:tal.galili@gmail.com" target="_blank">tal.galili@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div>Dear Wush and others,</div><div>Just to followup and say I've used this idea here:</div><div><a href="https://github.com/talgalili/dendextendRcpp/blob/master/src/cut_lower.cpp" target="_blank">https://github.com/talgalili/dendextendRcpp/blob/master/src/cut_lower.cpp</a></div>


<div><br></div><div>In general, it would have been better for me, where it possible to do some (or all) of the things below:</div><div>1) Get the length of a List</div><div>2) Change the attribute of elements within a list</div>


<div>3) Have this not happen:</div><div><div style="font-family:arial,sans-serif;font-size:12.800000190734863px"><div><br></div><div><div>require(Rcpp)</div><div>cppFunction('</div><div>            SEXP temp(List x){</div>


<div>            return(x);</div><div class="im"><div>            }</div><div>            ')</div><div>x = list(structure(1L, animal = "cat"))</div><div>temp(x)</div></div><div>temp(x[[1]]) # I wish this didn't happen</div>
</div>

<div><br></div><div>(I'm possibly missing out things, but I thought of listing it just in case)</div><div><br></div><div><br></div><div>Many thanks for the help!</div><span class="HOEnZb"><font color="#888888"><div>Tal</div>
<div><br></div></font></span></div></div><div><br>

</div><div><br></div><div><br></div></div><div class="gmail_extra"><div class="im"><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><div><div class="h5"><div class="gmail_quote">On Tue, Aug 20, 2013 at 12:25 PM, Tal Galili <span dir="ltr"><<a href="mailto:tal.galili@gmail.com" target="_blank">tal.galili@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div dir="ltr">Hello Wush,<div>Indeed, thank you!</div><div><br></div><div>I will write more on this after I finish the code, since there are some bits which are a mystery to me. </div><span><font color="#888888"><div>

<br></div><div>Tal</div></font></span></div><div class="gmail_extra"><div>
<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><div><div><div class="gmail_quote">On Tue, Aug 20, 2013 at 12:13 PM, Wush Wu <span dir="ltr"><<a href="mailto:wush978@gmail.com" target="_blank">wush978@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">



<div dir="ltr">Hi Tal, <div><br></div><div>```</div><div><div><div>cppFunction('</div><div>std::vector<RObject>  temp2_fail(RObject x){</div><div>   std::vector<RObject> lower;</div></div><div>   List x_list(wrap(x));</div>





<div>   int n = x_list.size();</div><div>   lower.push_back(x);</div><div>   return(lower) ;</div><div>}</div><div>            ')</div><div class="gmail_extra">```</div><div class="gmail_extra"><br></div><div class="gmail_extra">





Is this what you want?</div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/8/20 Tal Galili <span dir="ltr"><<a href="mailto:tal.galili@gmail.com" target="_blank">tal.galili@gmail.com</a>></span><br>




<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div>
<div dir="ltr"><div>Dear list members,</div><div><br></div><div>I would like to be able to get an element pushed with its attributes, and I came across the following problem:</div><div><br></div><div><div>cppFunction('</div>







<div>std::vector<List>  temp(List x){</div><div>   std::vector<List> lower;</div><div>   lower.push_back(x);</div><div>   return(lower) ;</div><div>}</div><div>            ')</div><div>x = list(structure(1L, animal = "cat"))</div>







<div>temp(x)</div><div>temp(x[1])</div><div>temp(x[[1]]) # is there a way to not make this output without attributes?</div></div><div><br></div><div><br></div><div><br></div><div>If I use RObject, it will solve it, but then I would later not be able to iterate over the object, because I can't seem to get the .size() of an RObject.</div>







<div><br></div><div>Here is the code with the RObject:</div><div><div><br></div><div><br></div><div>cppFunction('</div><div>std::vector<RObject>  temp2(RObject x){</div><div>   std::vector<RObject> lower;</div>







<div>   lower.push_back(x);</div><div>   return(lower) ;</div><div>}</div><div>            ')</div><div>x = list(structure(1L, animal = "cat"))</div><div>temp2(x)</div><div>temp2(x[1])</div><div>temp2(x[[1]]) # Now it works as I want, but the following wouldn't work:</div>







</div><div><br></div><div><br></div><div><br></div><div><div><br></div><div>cppFunction('</div><div>std::vector<RObject>  temp2_fail(RObject x){</div><div>   std::vector<RObject> lower;</div><div>   int n x.size();</div>







<div>   lower.push_back(x);</div><div>   return(lower) ;</div><div>}</div><div>            ')</div></div><div><br></div><div><br></div><div><br></div><div>Any ideas?</div><div><br></div><div><br></div><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>
</div>
<br></div></div>_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" target="_blank">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br></blockquote></div><br></div></div></div>
</blockquote></div><br></div></div></div>
</blockquote></div><br></div></div></div>
<br>_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br></blockquote></div><br></div>