My task it to rewrite a R function in C++ to accelerate the while loops. All R codes has been rewritten in the help of Rcpp and Armadillo except the .Fortran()
. I try to use Rinside to at first and it works at a very slow speed as Dirk indicated. (It is expensive for data to go through R -> C++ -> R -> Fortran)
Since I don't want to rewrite the Fortran codes in C++ and vice versa, it looks natural to accelerate the programs by linking C++ directly to Fortran: R -> C++ -> Fortran.
// [[Rcpp::depends(RcppArmadillo)]]
#include <RcppArmadillo.h>
using namespace Rcpp;
extern "C"{
List f_(int *n,NumericMatrix a, NumericVector c, double* eps);
}
The problem is that I can integrate C++ with Fortran and integrate R with C++, but I can't make these three things work together!
I try to compile the C++ in Linux but it just can't find RcppArmadillo.h
and namespace Rcpp
:
error: RcppArmadillo.h: No such file or directory
error: 'Rcpp' is not a namespace-name
When I call sourceCpp("test.cpp")
in R directly, the console would display:
test.o:test.cpp:(.text+0x20b2): undefined reference to `f_'
collect2: ld returned 1 exit status
Error in sourceCpp("test.cpp") : Error occurred building shared library.
I also try to combine all these things in a package by
RcppArmadillo::RcppArmadillo.package.skeleton("TTTest")
But I don't know how to deal with the package TTTest
(I believe it could not be installed) after I add the .cpp
and .f
files to /src
and run compileAttributes
.
So, is it possible to do things like what I imagine by Rcpp? Or it is necessary to convert Fortran codes to C/C++ codes?
Thanks for your help.
include "RcppArmadillo.h"
but it still cant find the other header files. And I doubt that to compile the file with Rcpp woud take more time since finally I would call the function in R – Cawley