Two possible solutions:
The 'quick-and-dirty', solution -- include the function declaration in the file where you use it:
#include <Rcpp.h>
using namespace Rcpp;
// declare fun1
int fun1(int a1);
// [[Rcpp::export]]
Rcpp::NumericVector fun(Rcpp::NumericVector data1)
{
NumericVector fun_data = data1;
int n = data1.size();
for(i=0;i<n;i++){
fun_data[i] = fun1(fun_data[i]);
}
return(fun_data);
}
The more robust solution: write header files that declare the functions, which can then be #include
-ed in each file. So you might have a header file fun1.h
in the same src
directory:
#ifndef PKG_FOO1_H
#define PKG_FOO1_H
int foo(int);
#endif
which you could then use with something like:
#include <Rcpp.h>
#include "fun1.h"
using namespace Rcpp;
// [[Rcpp::export]]
Rcpp::NumericVector fun(Rcpp::NumericVector data1)
{
NumericVector fun_data = data1;
int n = data1.size();
for(i=0;i<n;i++){
fun_data[i] = fun1(fun_data[i]);
}
return(fun_data);
}
As you progress, you're going to need to learn more C++ programming skills, so I recommend checking out one of the books here; in particular, Accelerated C++ is a great introduction.