I want to add a Fortran routine (from a package that I found on the internet) to my own R package. My R package compiles just fine, and so does the package with the Fortran code, but when I add that code to my package I get an error. I have come up with the following toy example
R code in R folder
#' @export
testfun<-function() { addc(1,2) + add_Fortran(1,2) }
#' @useDynLib testpac addf
#' @export
add_Fortran <- function(x, y) {
.Fortran(addf, x, y, numeric(1))[[3]]
}
C and Fortran Code in src folder
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
double addc(double x, double y) {
return x*y;
}
subroutine addf(x, y, answer)
double precision x, y, answer
answer = x + y
end
and now when I run devtools::document() I get the error
from 1mRcppExports.cpp:4:
1mRcppExports.cpp:28:34: 1;31merror: '1maddf_' was not declared in this scope
28 | {"addf", (DL_FUNC) &F77_NAME(1;31maddf), 3},
| 1;31m^~~~
1mC:/R/include/R_ext/RS.h:104:25: 1;36mnote: in definition of macro '1mF77_CALL'
104 | # define F77_CALL(x) 1;36mx ## _
| 1;36m^
1mRcppExports.cpp:28:25: 1;36mnote: in expansion of macro '1mF77_NAME'
28 | {"addf", (DL_FUNC) &1;36mF77_NAME(addf), 3},
| 1;36m^~~~~~~~
make: *** [C:/R/etc/x64/Makeconf:296: RcppExports.o] Error 1
ERROR: compilation failed for package 'testC'
So somehow I need to declare the routine addf somewhere, but I have not been able to find out how or where.
Wolfgang