[Rd] From .Fortran to .Call?
Koenker, Roger W
rkoenker @end|ng |rom ||||no|@@edu
Sat Dec 19 18:04:59 CET 2020
There are comments in various places, including R-extensions §5.4 suggesting that .Fortran is (nearly)
deprecated and hinting that use of .Call is more efficient and now preferred for packages. I understand
and greatly appreciate its use with dyn.load() and R CMD SHLIB for development workflow.
In an effort to modernize my quantreg package I wanted to solicit some advice
about whether it was worthwhile to move away from .Fortran, and if so how this
might be most expeditiously carried out.
As things currently stand my src directory has, in addition to couple dozen .f
files, a file called quantreg_init.c that contains
#include <R_ext/RS.h>
#include <stdlib.h> // for NULL
#include <R_ext/Rdynload.h>
/* .Fortran calls */
extern void F77_NAME(brutpow)(void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *);
extern void F77_NAME(combin)(void *, void *, void *, void *, void *, void *, void *);
extern void F77_NAME(crqf)(void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *);
…
static const R_FortranMethodDef FortranEntries[] = {
{"brutpow", (DL_FUNC) &F77_NAME(brutpow), 14},
{"combin", (DL_FUNC) &F77_NAME(combin), 7},
{"crqf", (DL_FUNC) &F77_NAME(crqf), 26},
...
void R_init_quantreg(DllInfo *dll)
{
R_registerRoutines(dll, CEntries, NULL, FortranEntries, NULL);
R_useDynamicSymbols(dll, FALSE);
}
This was originally setup by an experienced R person in about 2006, but has
always been rather opaque to me; I just follow the template to add fortran
functions. My questions are: what would I need to do beyond replacing
.Fortran calls by .Call in my R code? And would it help? Obviously, what
I’m dreading is being told that all those “void”s would have to be specified
more explicitly even though they are already specified in the fortran. My willingness to
embarrass myself by writing this message was triggered by comparing
timings of a prototype function in R and its fortranization in which the
prototype was actually faster. Thanks in advance for any suggestions.
More information about the R-devel
mailing list