javarrenjin

How to use Renjin Maven plugin with c and fortran


I'm trying to use "Renjin Maven plugin" to convert an R package to a jar that I can use with renjin in java. There is a description here: http://docs.renjin.org/en/latest/writing-renjin-extensions.html#renjin-maven-plugin on how to create the project, and I have managed to create it and build a jar with the r files converted, but I cannot see how to include c and fortran files.

Renjin does it for you if the package is in https://cran.r-project.org/ so I know it is possible. The package I'm using unfortunetely isn't in cran.

I have tried including the c files in the src/main/R folder and tried putting it in an src/main/c folder and they are ignored in both cases.


Solution

  • The renjin-maven-plugin supports converting c and fortran code into JVM bytecode. This section of the renjin-maven-plugin does the trick:

     <execution>
            <id>gnur-compile</id>
            <phase>compile</phase>
            <goals>
                <goal>gnur-compile</goal>
            </goals>
     </execution>
    

    See mjkallens answer to a similar question here. Basically what you do is

    1. download the source code for the latest version of ctsmr
    2. Unpack to a dir of choice
    3. Add a pom.xml file that calls the renjin maven plugin
    4. Add a Vagrant file similar to the one use to build the Renjin project itself to get the right versions of gcc etc. so that the renjin maven plugin can process the c and fortran sources.
    5. start vagrant and run mvn clean install

    I created an example on github which should give you some ideas on the details.