<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hi list,<br>
<br>
I am writing a Rcpp function (referred as f2). To be able to debug
it, I am currently using inline to write f2. f2 uses a function that
I've wrote and is now part of a package that I have made (referred
as f1). f1 is an Rcpp function that is not called within R but only
called from Rcpp functions. I was wondering how I could use this f1
function within f2 when using inline. From what I understand I
should be able to use the argument includes from cxxfunction. I
think it is related to this thread:<br>
<a class="moz-txt-link-freetext" href="http://thread.gmane.org/gmane.comp.lang.r.rcpp/2593/focus=2600">http://thread.gmane.org/gmane.comp.lang.r.rcpp/2593/focus=2600</a><br>
But I can't quite figure out.<br>
<br>
Here is a small example: <br>
<br>
library(inline)<br>
library(fxwithinfx) # My package that contain f1<br>
<br>
src <- '<br>
using namespace Rcpp;<br>
double y = 9;<br>
NumericVector z(1);<br>
<br>
f1(y, z);<br>
z[0] = z[0] + 1;<br>
return z;<br>
'<br>
f2 <- cxxfunction(signature(), body = src, plugin = "Rcpp",
includes = "#include <fxwithinfx/f1.h>")<br>
<br>
# I get the following error:<br>
<span class="Apple-style-span" style="border-collapse: separate;
color: rgb(0, 0, 0); font-family: 'Lucida Console'; font-size:
13px; font-style: normal; font-variant: normal; font-weight:
normal; letter-spacing: normal; line-height: 15px; orphans: 2;
text-align: -webkit-left; text-indent: 0px; text-transform: none;
white-space: pre-wrap; widows: 2; word-spacing: 0px;
-webkit-border-horizontal-spacing: 0px;
-webkit-border-vertical-spacing: 0px;
-webkit-text-decorations-in-effect: none;
-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;
background-color: rgb(225, 226, 229); ">
<pre tabindex="0" class="GNCMI-3DP5" style="font-family: 'Lucida Console'; font-size: 10pt !important; outline-style: none; outline-width: initial; outline-color: initial; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; white-space: pre-wrap !important; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 1.2; "><span class="GNCMI-3DK5">Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! file11741d6932c4.cpp:19:27: fatal error: fxwithinfx/f1.h: No such file or directory
compilation terminated.
# I tried to change the reference to f1.h by changing the path, but whatever path I give I still get an error. For example, if I use this instead:
f2 <- cxxfunction(signature(), body = src, plugin = "Rcpp",
includes = "#include <C:/Users/Marie/Documents/R/fxwithinfx/src/f1.h>")
# I get the following error:
</span><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Lucida Console'; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 15px; orphans: 2; text-align: -webkit-left; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(225, 226, 229); "><pre tabindex="0" class="GNCMI-3DP5" style="font-family: 'Lucida Console'; font-size: 10pt !important; outline-style: none; outline-width: initial; outline-color: initial; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; white-space: pre-wrap !important; margin-top: 0px; margin-right: 0px; margi
n-bottom: 0px; margin-left: 0px; line-height: 1.2; "><span class="GNCMI-3DK5">Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! file11743a6031d8.o:file11743a6031d8.cpp:(.text+0x104): undefined reference to `f1'
collect2: ld returned 1 exit status</span></pre></span><span class="GNCMI-3DK5"># I'm actually not sure whether I should refer the actual .h location or to the location within my R libraries
# Here are the header and src codes for the f1
f1.h:
#ifndef _fxwithinfx_f1_H
#define _fxwithinfx_f1_H
#include <Rcpp.h>
extern "C" int f1(double y, SEXP z) ;
#endif
f1.cpp:
#include "f1.h"
int f1(double y, SEXP z){
using namespace Rcpp;
NumericVector zz(z);
zz[0] = y + 1.5;
}
</span></pre>
</span><br>
<br>
Any help will be appreciated!<br>
<br>
Marie<br>
<br>
</body>
</html>