<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">Hi,</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">I'd like to dynamically add functions to a module when I call one of its function. Later I will want to do the same for classes too, so that to create classes "on the fly".</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><br></div><div class="gmail_default"><span style="font-family:arial,helvetica,sans-serif;font-size:small">But for the moment, here is what I try to do and it doesn't work, because I can't see my dynamically created function in R</span></div><div class="gmail_default"><span style="color:rgb(0,0,153)"><br></span></div><div class="gmail_default"><span style="color:rgb(0,0,153)">#include <Rcpp.h></span><br></div><div class="gmail_default"><pre style="color:rgb(0,0,0)"><span class="gmail-keyword" style="color:rgb(153,0,0)">using namespace</span> Rcpp<span class="gmail-operator" style="color:rgb(102,51,0);font-weight:bold">;</span><span class="gmail-type" style="color:rgb(255,102,51)">

double</span> foobar<span class="gmail-operator" style="color:rgb(102,51,0);font-weight:bold">(</span><span class="gmail-type" style="color:rgb(255,102,51)">int</span> x<span class="gmail-operator" style="color:rgb(102,51,0);font-weight:bold">)
{</span><span class="gmail-flow" style="color:rgb(255,0,0)">
    return</span> x<span class="gmail-operator" style="color:rgb(102,51,0);font-weight:bold">*</span><span class="gmail-float" style="color:rgb(153,102,0)">2.0</span><span class="gmail-operator" style="color:rgb(102,51,0);font-weight:bold">;
}</span><span class="gmail-type" style="color:rgb(255,102,51)">

void</span> makef<span class="gmail-operator" style="color:rgb(102,51,0);font-weight:bold">()
{</span>
    function<span class="gmail-operator" style="color:rgb(102,51,0);font-weight:bold">(</span><span class="gmail-string" style="color:rgb(0,153,0)">"dynfoo"</span><span class="gmail-operator" style="color:rgb(102,51,0);font-weight:bold">,&</span>foobar<span class="gmail-operator" style="color:rgb(102,51,0);font-weight:bold">);
}</span>

RCPP_MODULE<span class="gmail-operator" style="color:rgb(102,51,0);font-weight:bold">(</span>test1<span class="gmail-operator" style="color:rgb(102,51,0);font-weight:bold">)
{</span>
    function<span class="gmail-operator" style="color:rgb(102,51,0);font-weight:bold">(</span><span class="gmail-string" style="color:rgb(0,153,0)">"foobar"</span><span class="gmail-operator" style="color:rgb(102,51,0);font-weight:bold">,</span>foobar<span class="gmail-operator" style="color:rgb(102,51,0);font-weight:bold">);</span>
    function<span class="gmail-operator" style="color:rgb(102,51,0);font-weight:bold">(</span><span class="gmail-string" style="color:rgb(0,153,0)">"makef"</span><span class="gmail-operator" style="color:rgb(102,51,0);font-weight:bold">,&</span>makef<span class="gmail-operator" style="color:rgb(102,51,0);font-weight:bold">);
}</span></pre></div><div class="gmail_default">Then in R, I call the function makef hoping to see the function dynfoo appears in my global environment in R. It's not the case. I suspect a problem with scope (or something like that) ?</div><div class="gmail_default"><br></div><div class="gmail_default">- What is the correct way to do that ?</div><div class="gmail_default">- Can I create my functions in other environment too ?</div><div class="gmail_default"><br></div><div class="gmail_default">Best,<br>David</div><div class="gmail_default"><br></div></div>