<div><br></div>hi dirk---it is indeed excellent.  alas, it doesn't cover my confusion.<div><br></div><div><b>general</b>: I now realize my first problem with the print function.  I need to double-escape '\'.</div>

<div><font face="courier new, monospace">   cppFunction('int hello(int i) { printf("hello, world\n"); }')</font></div><div>is wrong.  it needs to be</div><div><font face="courier new, monospace">   cppFunction('int hello(int i) { printf("hello, world\\n"); }')</font></div>

<div>gotcha!</div><div><br></div><div><div><b><br class="Apple-interchange-newline">S2.9</b>: the cppFunction works without the attributes in this examples.  what determines whether one needs to declare attributes vs. Rcpp being smart enough to figure it out itself?  in any case, this works:</div>

</div><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><div><font face="courier new, monospace">library( Rcpp )</font></div><div><font face="courier new, monospace"><br></font></div><div>
<font face="courier new, monospace">cppFunction('</font></div>
<div><font face="courier new, monospace">struct silly { int a; double *b; };</font></div><div><font face="courier new, monospace">// [[Rcpp::export]]</font></div><div><font face="courier new, monospace">long initme(int i) {</font></div>

<div><font face="courier new, monospace">  silly *s= new silly;</font></div><div><font face="courier new, monospace">  s->a=i; s->b=new double[i+1];</font></div><div><font face="courier new, monospace">  return (long) s;</font></div>

<div><font face="courier new, monospace">}</font></div><div><font face="courier new, monospace">')</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">cat("Compiled OK\n")</font></div>

</div><div><font face="courier new, monospace">x <- initme(5)</font></div></blockquote><div><div><font face="courier new, monospace"><br></font></div><div><font face="arial, helvetica, sans-serif">although this works, I still get a warning.</font></div>

<div><font face="arial, helvetica, sans-serif"><br class="Apple-interchange-newline"></font><font face="courier new, monospace">   No function found for Rcpp::export attribute at file284a5ab1f09.cpp:5 </font></div><div><br>

</div><div>but R has picked up the initme() function.  it's a good start.</div></div><div><br></div><div>I presume long is the wrong return type.  (void*) did not work.  what is the recommended pointer type?</div><div>

<br></div><div>And somehow I need to figure out how to tell R to call a destructor when the x object goes out of scope.</div><div><br></div><div><br></div><div>I don't want to take your time any longer, so I think it is better for me to give up here.</div>

<div><br></div><div>regards,</div><div><br></div><div>/iaw</div><div><div><div>----</div><div>Ivo Welch (<a href="mailto:ivo.welch@gmail.com" target="_blank">ivo.welch@gmail.com</a>)</div></div><div><br></div><div><br></div>

<div class="gmail_quote">On Thu, May 30, 2013 at 3:39 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">

<div class="im"><br>
On 30 May 2013 at 15:08, ivo welch wrote:<br>
|<br>
| thx, dirk.  first, apologies for multiposting earlier.  I thought it did not<br>
| allow me to post from my non-registered email address.  second, apologies for<br>
| the private email.  I wasn't expecting any answers.  just wanted to help with<br>
| some feedback.  I will buy your Rcpp book when it comes out.<br>
|<br>
| I think you are correct that modules are too tough for me.  heck, I don't even<br>
| write R packages.  I am just an end user.  I would have to learn how to write<br>
| and build those first.  so, I think I will want to go the accessor function<br>
| route.  can cppFunction() allow me to define structures?  I am just trying<br>
| something super-simple here:<br>
|<br>
|<br>
|     library( Rcpp )<br>
|     cppFunction('<br>
|     struct Silly {<br>
|       double *v; int k;<br>
|     };<br>
|     void hello(int i) { printf("hello, world\n"); }<br>
|     ')<br>
|     cat("Compiled OK\n")<br>
|<br>
|<br>
| but it fails, both on the printf and on the structure definition.  I am<br>
| wondering whether cppFunction can just handle single functions and without<br>
| quotation marks.<br>
<br>
</div>You really should consider reading the excellent vignette 'Rcpp attributes'.<br>
<span class="HOEnZb"><font color="#888888"><br>
Dirk<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
|<br>
| regards,<br>
|<br>
| /iaw<br>
|<br>
| ----<br>
| Ivo Welch (<a href="mailto:ivo.welch@gmail.com">ivo.welch@gmail.com</a>)<br>
|  <br>
|<br>
|<br>
| On Thu, May 30, 2013 at 10:02 AM, Dirk Eddelbuettel <<a href="mailto:edd@debian.org">edd@debian.org</a>> wrote:<br>
|<br>
|<br>
|     Ivo,<br>
|<br>
|     Appreciate that you post here.  Am a little pressed for time but in a<br>
|     nutshell, you missed that the new (and very nice) Rcpp Attributes which you<br>
|     use for sourceCpp do NOT currently mix with Rcpp Modules.<br>
|<br>
|     So either concentrate on easily writing accessor function, OR concentrate<br>
|     on<br>
|     using Modules (which is not th easiest topic to start with). You cannot mix<br>
|     and match.<br>
|<br>
|     As for simplest examples: they are eg in the package itself, look at<br>
|<br>
|        /usr/local/lib/R/site-library/Rcpp/unitTests/testRcppModule/<br>
|<br>
|     which provides a small but complete working package using modules.<br>
|<br>
|     Hope this helps,  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>
|<br>
|<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>