Search code examples
rpackagecran

Fortran code and Found no calls to: 'R_registerRoutines', 'R_useDynamicSymbols'


When I submit my package to cran I get the error as Found no calls to: 'R_registerRoutines', 'R_useDynamicSymbols' It is good practice to register native routines and to disable symbol search. My package was tested in this version of R by CRAN:

R version 3.4.0 alpha (2017-03-28 r72427)

Note that there is a solution for this error here R CMD check note: Found no calls to: ‘R_registerRoutines’, ‘R_useDynamicSymbols’ but my external codes are in Fortran and tried the procedure described there but does not fix the issue for me. What can I do to overcome the issue? Thanks

Update: Following the procedure described https://www.r-bloggers.com/1-easy-package-registration/ I could pass the

Error:Found no calls to: ‘R_useDynamicSymbols’

But Found no call to: 'R_registerRoutines' still remains.


Solution

  • I solved the problem and you may find it useful for your own case. Let's assume you have a subroutine called myf.f90 in src directory with following content:

        SUBROUTINE cf(r,cd,loci)
        INTEGER::r,cd
        DOUBLE PRECISION::loci
    ....
    ....
    ....
        END SUBROUTINE cf
    

    To register this you need to do the following :

    A) Run tools::package_native_routine_registration_skeleton("package directory")

    B) Edit the output; for the example above would be:

    #include <R.h>
    #include <Rinternals.h>
    #include <stdlib.h> // for NULL
    #include <R_ext/Rdynload.h>
    
    /* FIXME:
    Check these declarations against the C/Fortran source code.
    */
    
    /* .Fortran calls */
    extern void F77_NAME(cf)(int *r, int *cd, double *loci);
    
    static const R_FortranMethodDef FortranEntries[] = {
      {"cf", (DL_FUNC) &F77_NAME(cf),  3},
      {NULL, NULL, 0}
    };
    
    void R_init_packagename(DllInfo *dll)
    {
      R_registerRoutines(dll, NULL, NULL, FortranEntries, NULL);
      R_useDynamicSymbols(dll, FALSE);
    }
    

    C) Copy and paste the full output in a packagename_init.c file to be put in src/

    D) Update NAMESPACE, verifying that useDynLib(packagename, .registration = TRUE)