Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have successfully done this, calling math functions from R via weave.inline() code (under Ubuntu Linux).</p> <p>First, compile your C functions as a shared library. In my case, I grabbed a recent release of R from CRAN, and did</p> <pre><code>./configure --enable-R-static-lib --enable-static --with-readline=no cd src/nmath/standalone/ make </code></pre> <p>You should now have a file called <code>libRmath.so</code>. If <code>libpath</code> is a string with the directory that holds <code>libRmath.so</code>, you can do something like</p> <pre><code>code = 'return_val = pbinom(100, 20000, 100./20000., 0, 1);' support_code = 'extern "C" double pbinom(double x, double n, double p, int lower_tail, int log_p);' weave.inline(code, support_code=support_code, library_dirs=[libpath], libraries=["Rmath"], runtime_library_dirs=[libpath]) </code></pre> <p>Note a couple things. The header declarations have to go in <code>support_code</code>, not <code>code</code> (I don't know why), and they have to be prefixed with <code>extern "C"</code> because they're C code, not C++ (this is standard). It should be possible to include headers files instead of using <code>support_code</code> (check the docs for weave.inline), but I haven't tried it. The library name is <code>Rmath</code>, but the shared library file is <code>libRmath.so</code>, in the usual Unix convention. And the path to the library is specified twice, once for linking, and once for execution.</p> <p>Hope this helps!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload