<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"Lucida Console";
        panose-1:2 11 6 9 4 5 4 2 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
span.apple-style-span
        {mso-style-name:apple-style-span;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;}
span.gdxa2evbhab
        {mso-style-name:gdxa2evbhab;}
span.gdxa2evbl5
        {mso-style-name:gdxa2evbl5;}
span.gdxa2evbp5
        {mso-style-name:gdxa2evbp5;}
span.EmailStyle23
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal" style="margin-bottom:12.0pt">I am a new Rcpp user, and I have been trying to do a simple exercise of generating random numbers to put into a vector.  To start off, the following code works:<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto"><span style="font-size:10.0pt;font-family:"Lucida Console";color:blue">> code <- 'Rcpp::RNGScope scope;
</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto"><span style="font-size:10.0pt;font-family:"Lucida Console";color:blue">+          Rcpp::NumericVector rn(5);</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto"><span style="font-size:10.0pt;font-family:"Lucida Console";color:blue">+          rn = rnorm(5,0,1);</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto"><span style="font-size:10.0pt;font-family:"Lucida Console";color:blue">+          return Rcpp::wrap(rn);</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto"><span style="font-size:10.0pt;font-family:"Lucida Console";color:blue">+ '</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto"><span style="font-size:10.0pt;font-family:"Lucida Console";color:blue">>
</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto"><span style="font-size:10.0pt;font-family:"Lucida Console";color:blue">> fun <- cxxfunction(body=code, plugin="Rcpp")</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto"><span style="font-size:10.0pt;font-family:"Lucida Console"">cygwin warning:</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto"><span style="font-size:10.0pt;font-family:"Lucida Console"">  MS-DOS style path detected: C:/R/R-215~1.1/etc/i386/Makeconf</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto"><span style="font-size:10.0pt;font-family:"Lucida Console"">  Preferred POSIX equivalent is: /cygdrive/c/R/R-215~1.1/etc/i386/Makeconf</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto"><span style="font-size:10.0pt;font-family:"Lucida Console"">  CYGWIN environment variable option "nodosfilewarning" turns off this warning.</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto"><span style="font-size:10.0pt;font-family:"Lucida Console"">  Consult the user's guide for more details about POSIX paths:</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto"><span style="font-size:10.0pt;font-family:"Lucida Console"">   
<a href="http://cygwin.com/cygwin-ug-net/using.html#using-pathnames">http://cygwin.com/cygwin-ug-net/using.html#using-pathnames</a></span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto"><span style="font-size:10.0pt;font-family:"Lucida Console";color:blue">>
</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto"><span style="font-size:10.0pt;font-family:"Lucida Console";color:blue">> (res <- fun())</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:10.0pt;font-family:"Lucida Console"">[1]  1.7517515  0.3178733 -0.6957581  1.7030360 -1.6546936</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-line-height-alt:8.25pt"><br>
<br>
When I try to do the same thing, but in a loop as shown here:<br>
<br>
<span style="color:#1F497D"><o:p></o:p></span></p>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"><o:p> </o:p></span></pre>
<pre><span class="gdxa2evbhab"><span style="font-family:"Lucida Console";color:blue;background:#E1E2E5">> </span></span><span class="gdxa2evbl5"><span style="font-family:"Lucida Console";color:blue;background:#E1E2E5">code <- 'Rcpp::RNGScope scope; <o:p></o:p></span></span></pre>
<pre><span class="gdxa2evbhab"><span style="font-family:"Lucida Console";color:blue;background:#E1E2E5">+ </span></span><span class="gdxa2evbhab"><span style="font-family:"Lucida Console";color:#1F497D;background:#E1E2E5"> </span></span><span class="gdxa2evbl5"><span style="font-family:"Lucida Console";color:blue;background:#E1E2E5">        Rcpp::NumericVector rn(5);<o:p></o:p></span></span></pre>
<pre><span class="gdxa2evbhab"><span style="font-family:"Lucida Console";color:blue;background:#E1E2E5">+ </span></span><span class="gdxa2evbl5"><span style="font-family:"Lucida Console";color:blue;background:#E1E2E5">         for (int i=0; i < 5; i++) {<o:p></o:p></span></span></pre>
<pre><span class="gdxa2evbhab"><span style="font-family:"Lucida Console";color:blue;background:#E1E2E5">+ </span></span><span class="gdxa2evbl5"><span style="font-family:"Lucida Console";color:blue;background:#E1E2E5">           rn(i) = rnorm(1,0,1); <o:p></o:p></span></span></pre>
<pre><span class="gdxa2evbhab"><span style="font-family:"Lucida Console";color:blue;background:#E1E2E5">+ </span></span><span class="gdxa2evbl5"><span style="font-family:"Lucida Console";color:blue;background:#E1E2E5">         }<o:p></o:p></span></span></pre>
<pre><span class="gdxa2evbhab"><span style="font-family:"Lucida Console";color:blue;background:#E1E2E5">+ </span></span><span class="gdxa2evbl5"><span style="font-family:"Lucida Console";color:blue;background:#E1E2E5">         return Rcpp::wrap(rn);<o:p></o:p></span></span></pre>
<pre><span class="gdxa2evbhab"><span style="font-family:"Lucida Console";color:blue;background:#E1E2E5">+ </span></span><span class="gdxa2evbl5"><span style="font-family:"Lucida Console";color:blue;background:#E1E2E5">'<o:p></o:p></span></span></pre>
<pre><span class="gdxa2evbhab"><span style="font-family:"Lucida Console";color:blue;background:#E1E2E5">> </span></span><span class="gdxa2evbl5"><span style="font-family:"Lucida Console";color:blue;background:#E1E2E5"><o:p></o:p></span></span></pre>
<pre><span class="gdxa2evbhab"><span style="font-family:"Lucida Console";color:blue;background:#E1E2E5">> </span></span><span class="gdxa2evbl5"><span style="font-family:"Lucida Console";color:blue;background:#E1E2E5">fun <- cxxfunction(body=code, plugin="Rcpp")</span></span><o:p></o:p></pre>
<p class="MsoNormal" style="mso-line-height-alt:8.25pt"><br>
the result is an error message indicating that it cannot convert a NumericVector to double.  Since in the first example I did not index, I am assuming that I have indexed incorrectly, but I can't see how.  Below is the detailed error message - any idea what
 I am doing wrong?<br>
<br>
<br>
<span class="apple-style-span"><span style="font-size:7.0pt"><o:p></o:p></span></span></p>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"><o:p> </o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"><o:p> </o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5">cygwin warning:<o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5">  MS-DOS style path detected: C:/R/R-215~1.1/etc/i386/Makeconf<o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5">  Preferred POSIX equivalent is: /cygdrive/c/R/R-215~1.1/etc/i386/Makeconf<o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5">  CYGWIN environment variable option "nodosfilewarning" turns off this warning.<o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5">  Consult the user's guide for more details about POSIX paths:<o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5">    <a href="http://cygwin.com/cygwin-ug-net/using.html#using-pathnames">http://cygwin.com/cygwin-ug-net/using.html#using-pathnames</a><o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5">file15182ecd2ee.cpp: In function 'SEXPREC* file15182ecd2ee()':<o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5">file15182ecd2ee.cpp:33:31: error: cannot convert 'Rcpp::NumericVector {aka Rcpp::Vector<14>}' to 'Rcpp::traits::storage_type<14>::type {aka double}' in assignment<o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5">make: *** [file15182ecd2ee.o] Error 1<o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"><o:p> </o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5">ERROR(s) during compilation: source code errors or compiler configuration errors!<o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"><o:p> </o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5">Program source:<o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5">  1: <o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5">  2: // includes from the plugin<o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5">  3: <o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5">  4: #include <Rcpp.h><o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5">  5: <o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5">  6: <o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5">  7: #ifndef BEGIN_RCPP<o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5">  8: #define BEGIN_RCPP<o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5">  9: #endif<o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"> 10: <o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"> 11: #ifndef END_RCPP<o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"> 12: #define END_RCPP<o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"> 13: #endif<o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"> 14: <o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"> 15: using namespace Rcpp;<o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"> 16: <o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"> 17: <o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"> 18: // user includes<o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"> 19: <o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"> 20: <o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"> 21: // declarations<o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"> 22: extern "C" {<o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"> 23: SEXP file15182ecd2ee( ) ;<o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"> 24: }<o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"> 25: <o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"> 26: // definition<o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"> 27: <o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"> 28: SEXP file15182ecd2ee(  ){<o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"> 29: BEGIN_RCPP<o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"> 30: Rcpp::RNGScope scope; <o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"> 31:          Rcpp::NumericVector rn(5);<o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"> 32:          for (int i=0; i < 5; i++) {<o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"> 33:            rn(i) = rnorm(1,0,1); <o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"> 34:          }<o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"> 35:          return Rcpp::wrap(rn);<o:p></o:p></span></pre>
<pre style="mso-line-height-alt:8.25pt"><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"> 36: <br><br></span><span class="apple-style-span"><span style="font-size:7.0pt;font-family:"Lucida Console";color:black;background:#E1E2E5"><o:p></o:p></span></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"><o:p> </o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"><o:p> </o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"> 37: END_RCPP<o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"> 38: }<o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"> 39: <o:p></o:p></span></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"> 40: <o:p></o:p></span></pre>
<pre><span class="gdxa2evbp5"><span style="font-family:"Lucida Console";color:black;background:#E1E2E5">Error in compileCode(f, code, language = language, verbose = verbose) : <o:p></o:p></span></span></pre>
<pre><span class="gdxa2evbp5"><span style="font-family:"Lucida Console";color:black;background:#E1E2E5">  Compilation ERROR, function(s)/method(s) not created! cygwin warning:<o:p></o:p></span></span></pre>
<pre><span class="gdxa2evbp5"><span style="font-family:"Lucida Console";color:black;background:#E1E2E5">  MS-DOS style path detected: C:/R/R-215~1.1/etc/i386/Makeconf<o:p></o:p></span></span></pre>
<pre><span class="gdxa2evbp5"><span style="font-family:"Lucida Console";color:black;background:#E1E2E5">  Preferred POSIX equivalent is: /cygdrive/c/R/R-215~1.1/etc/i386/Makeconf<o:p></o:p></span></span></pre>
<pre><span class="gdxa2evbp5"><span style="font-family:"Lucida Console";color:black;background:#E1E2E5">  CYGWIN environment variable option "nodosfilewarning" turns off this warning.<o:p></o:p></span></span></pre>
<pre><span class="gdxa2evbp5"><span style="font-family:"Lucida Console";color:black;background:#E1E2E5">  Consult the user's guide for more details about POSIX paths:<o:p></o:p></span></span></pre>
<pre><span class="gdxa2evbp5"><span style="font-family:"Lucida Console";color:black;background:#E1E2E5">    <a href="http://cygwin.com/cygwin-ug-net/using.html#using-pathnames">http://cygwin.com/cygwin-ug-net/using.html#using-pathnames</a><o:p></o:p></span></span></pre>
<pre><span class="gdxa2evbp5"><span style="font-family:"Lucida Console";color:black;background:#E1E2E5">file15182ecd2ee.cpp: In function 'SEXPREC* file15182ecd2ee()':<o:p></o:p></span></span></pre>
<pre><span class="gdxa2evbp5"><span style="font-family:"Lucida Console";color:black;background:#E1E2E5">file15182ecd2ee.cpp:33:31: error: cannot convert 'Rcpp::NumericVector {aka Rcpp::Vector<14>}' to 'Rcpp::traits::storage_type<14>::type {aka double}' in assignment<o:p></o:p></span></span></pre>
<pre><span class="gdxa2evbp5"><span style="font-family:"Lucida Console";color:black;background:#E1E2E5">make: *** [file15182ecd2ee.o] Error 1<o:p></o:p></span></span></pre>
<pre><span class="gdxa2evbp5"><span style="font-family:"Lucida Console";color:black;background:#E1E2E5">In addition: Warning message:<o:p></o:p></span></span></pre>
<pre><span class="gdxa2evbp5"><span style="font-family:"Lucida Console";color:black;background:#E1E2E5">running command 'C:/R/R-215~1.1/bin/i386/R CMD SHLIB file15182ecd2ee.cpp 2> file15182ecd2ee.cpp.err.txt' had status 1 </span></span><o:p></o:p></pre>
<pre><span style="font-family:"Lucida Console";color:black;background:#E1E2E5"><o:p> </o:p></span></pre>
<p class="MsoNormal" style="margin-bottom:12.0pt"><o:p> </o:p></p>
</div>
</body>
</html>