Hello Dirk,<br><br>That was everything I want to know in this example.<br>Thanks for helping me out, for your advice, and for such an amazing package.<br><br>Best,<br>Zhongyi<br><br><br><div class="gmail_quote">On Fri, Aug 5, 2011 at 11:21 AM, Dirk Eddelbuettel <span dir="ltr">&lt;<a href="mailto:edd@debian.org">edd@debian.org</a>&gt;</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;"><br>
Zhongyi,<br>
<div class="im"><br>
On 5 August 2011 at 04:05, Zhongyi Yuan wrote:<br>
| Hi Douglas,<br>
|<br>
| Thank you for the reply. That clarifies quite a bit.<br>
| But still, it does not explain the different behavior of those examples, does<br>
| it? One moment ago, I was thinking that the L suffix might have made it<br>
| constant and hence can&#39;t be modified. Looks like I am wrong. (And fun(1:3)<br>
| gives the same result too.)<br>
<br>
</div>Don&#39;t take this the wrong way but you man know too little R to get to what<br>
this is about. But please consider this difference:<br>
<br>
R&gt; typeof(1L)<br>
[1] &quot;integer&quot;<br>
R&gt; typeof(1)<br>
[1] &quot;double&quot;<br>
R&gt;<br>
<br>
In particular, both &#39;1&#39; and &#39;1.0&#39; get you a double.<br>
<br>
We added the example to show that when you use 1L:3L (eg an integer vector)<br>
and assign to a Rcpp::NumericVector you _do get a separate copy_ due to C++<br>
casting semantics.  The proper lightweight call is seq(1.0, 3.0, by=1.0)<br>
which then exhibits the shallow copy vs deep copy issue the rest of the<br>
example is about.<br>
<br>
This is somewhat advanced corner-case stuff so maybe you should not fret too<br>
too much about it now but come back to it later.<br>
<br>
Dirk<br>
<div><div></div><div class="h5"><br>
| Zhongyi<br>
|<br>
| On Fri, Aug 5, 2011 at 3:49 AM, Douglas Bates &lt;<a href="mailto:bates@stat.wisc.edu">bates@stat.wisc.edu</a>&gt; wrote:<br>
|<br>
|     On Fri, Aug 5, 2011 at 5:27 AM, Zhongyi Yuan &lt;<a href="mailto:yuanzygoso@gmail.com">yuanzygoso@gmail.com</a>&gt; wrote:<br>
|     &gt; Dear useR&#39;s,<br>
|     &gt;<br>
|     &gt; After I found Rcpp a few days ago, I&#39;ve been very excited collecting<br>
|     &gt; documents for learning. But still I find myself understand little.<br>
|     &gt; Here&#39;s a question I want you to help me with.<br>
|     &gt;<br>
|     &gt; In page 17 of Dirk and Romain&#39;s slides from part2 of the Apr 28 Rcpp<br>
|     &gt; workshop (here&#39;s a link:<br>
|     &gt; <a href="http://dirk.eddelbuettel.com/papers/rcpp_workshop_part_2_details.pdf" target="_blank">http://dirk.eddelbuettel.com/papers/rcpp_workshop_part_2_details.pdf</a>), I<br>
|     &gt; can&#39;t figure out why the two examples behave differently.<br>
|     &gt; And also, why are people using 1L:3L? What not just 1:3?<br>
|<br>
|     It happens that they are the same but only because 1:3 generates an<br>
|     integer sequence by default.  Most of the time 1 gives a double<br>
|     precision floating point number whereas 1L is an integer.  Those with<br>
|     long-time experience in writing R code tend to use the L when they<br>
|     know that an integer is wanted, just to bypass the conversion step.<br>
|<br>
|     &gt; Maybe I am asking silly question? But please do help me. I couldn&#39;t find<br>
|     an<br>
|     &gt; answer on google.<br>
|     &gt; Thank you.<br>
|     &gt;<br>
|     &gt; Best,<br>
|     &gt; Zhongyi<br>
|     &gt;<br>
|     &gt;<br>
|     &gt; _______________________________________________<br>
|     &gt; Rcpp-devel mailing list<br>
|     &gt; <a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
|     &gt; <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>
|     &gt;<br>
|     &gt;<br>
|<br>
|<br>
|<br>
</div></div>| ----------------------------------------------------------------------<br>
<div><div></div><div class="h5">| _______________________________________________<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>
<br>
</div></div><font color="#888888">--<br>
Gauss once played himself in a zero-sum game and won $50.<br>
                      -- #11 at <a href="http://www.gaussfacts.com" target="_blank">http://www.gaussfacts.com</a><br>
</font></blockquote></div><br>