Thanks Dirk.  Passing the addition function in the includes argument worked great.  <div><br></div><div>Also, one of the links from your suggested Google search led me to this (working) example for std::accumulate:</div><div>

<div><br></div><div>src &lt;- &#39;NumericVector xx(x);</div><div>return wrap( std::accumulate( xx.begin(), xx.end(), 0.0));&#39;</div><div>fx &lt;- cxxfunction(signature( x = &quot;numeric&quot; ),body=src,plugin = &quot;Rcpp&quot;)</div>

<div>fx(1:10)  # 55</div><div><br></div><div>I had been copying the quickref and using:  std::accumulate( xx.begin(), xx.end(),std::plus&lt;double&gt;(),0.0)</div><div><br></div><div>I think this might be a typo where the last two arguments are transposed (which I shouldn&#39;t have noticed after browsing the <a href="http://www.cppreference.com/wiki/algorithm/accumulate">function&#39;s c++ reference</a>), as the following works just fine:  std::accumulate( xx.begin(), xx.end(),0.0,std::plus&lt;double&gt;())</div>

<div><br></div><div>Chris</div><br><div class="gmail_quote">On Sat, May 14, 2011 at 5:29 PM, 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div class="im"><br>
On 14 May 2011 at 17:13, Chris DuBois wrote:<br>
| Thanks Dirk.  Quick newbie followup question: Can we put functions within the<br>
| inline C++ code?  The following doesn&#39;t compile, for example:<br>
| src &lt;- &#39;<br>
| int addition (int a, int b)<br>
| {<br>
|   int r;<br>
|   r=a+b;<br>
|   return (r);<br>
| }<br>
| NumericVector xx(x);<br>
| return(xx);<br>
| &#39;<br>
| testfun = cxxfunction(signature(x=&quot;numeric&quot;),body=src,plugin=&quot;Rcpp&quot;)<br>
<br>
</div>Use the &#39;verbose=TRUE&#39; to cxxfunction() and it will become clear<br>
why -- a function is written around the &#39;body=...&#39; argument,<br>
hence no chance that that part may contain another C++ function.<br>
<br>
The remedy is simple: use the &quot;include=...&quot; argument as in<br>
<br>
   inc &lt;- &#39;<br>
<div class="im">   int addition (int a, int b) {<br>
</div>     int r = a + b;<br>
     return (r);<br>
   }<br>
   &#39;<br>
<br>
   src = &#39;<br>
<div class="im">   NumericVector xx(x);<br>
   return(xx);<br>
   &#39;<br>
<br>
</div>   testfun = cxxfunction(signature(x=&quot;numeric&quot;), body=src, include=inc, plugin=&quot;Rcpp&quot;)<br>
<br>
<br>
That trick is used a couple of time in the documentation and examples.<br>
<div class="im"><br>
<br>
| On a related note, would you mind showing a quick working example using<br>
| std::accumulate?  The one below from the quick reference doesn&#39;t compile for<br>
| me.<br>
<br>
<br>
</div>Try Google for something like that, eg a query that is restricted to my site as in<br>
<br>
    site:<a href="http://dirk.eddelbuettel.com" target="_blank">dirk.eddelbuettel.com</a>  &quot;std::accumulate&quot;<br>
<br>
show five immediate hits.  You can similarly constrict the search<br>
to the rcpp-devel list.<br>
<br>
Can you send a small example for inline that shows how/where it quickref<br>
example fails for you?<br>
<div><div></div><div class="h5"><br>
Dirk<br>
<br>
--<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>
</div></div></blockquote></div><br></div>