问题
I have some local R libraries that I would like include in my renjin Java application. Some of the libraries are written entirely in R, some libraries have C++ dependencies and some libraries have S4 classes. Ideally, I don't want to maintain two copies of each library.
I am wondering if there is any automated way to take a local R library(or its sources) and generate a Renjin compatible version?
回答1:
All CRAN and Bioconductor packages listed at packages.renjin.org are compiled to Java bytecode (including C, C++ and Fortran sources) and packaged into a JAR from the original sources by a fully automated build system.
The Renjin documentation includes instructions on creating packages for Renjin, but for a package with only R code the difference with a package for GNU R is only the suggested (and thus optional) directory layout.
To build your own R package which follows GNU R's conventions for the directory structure, you must add only a Maven POM file which includes information on the location of the R source files. For example (note placeholders for package name and version):
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.renjin.cran</groupId>
<artifactId>YOUR PACKAGE NAME HERE</artifactId>
<version>YOUR PACKAGE VERSION HERE</version>
<distributionManagement>
<repository>
<id>renjin-packages</id>
<name>Renjin CI Repository</name>
<url>http://nexus.bedatadriven.com/content/repositories/renjin-packages</url>
</repository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>org.renjin</groupId>
<artifactId>methods</artifactId>
<version>0.8.2201</version>
</dependency>
<dependency>
<groupId>org.renjin</groupId>
<artifactId>datasets</artifactId>
<version>0.8.2201</version>
</dependency>
<dependency>
<groupId>org.renjin</groupId>
<artifactId>stats</artifactId>
<version>0.8.2201</version>
</dependency>
<dependency>
<groupId>org.renjin</groupId>
<artifactId>grDevices</artifactId>
<version>0.8.2201</version>
</dependency>
<dependency>
<groupId>org.renjin</groupId>
<artifactId>stats4</artifactId>
<version>0.8.2201</version>
</dependency>
<dependency>
<groupId>org.renjin</groupId>
<artifactId>tools</artifactId>
<version>0.8.2201</version>
</dependency>
<dependency>
<groupId>org.renjin</groupId>
<artifactId>utils</artifactId>
<version>0.8.2201</version>
</dependency>
<dependency>
<groupId>org.renjin</groupId>
<artifactId>graphics</artifactId>
<version>0.8.2201</version>
</dependency>
<dependency>
<groupId>org.renjin</groupId>
<artifactId>compiler</artifactId>
<version>0.8.2201</version>
<scope>provided</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>bedatadriven-public</id>
<url>http://nexus.bedatadriven.com/content/groups/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>bedatadriven-public</id>
<url>http://nexus.bedatadriven.com/content/groups/public/</url>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<groupId>org.renjin</groupId>
<artifactId>renjin-maven-plugin</artifactId>
<version>0.8.2201</version>
<executions>
<execution>
<id>renjin-compile</id>
<phase>process-classes</phase>
<goals>
<goal>namespace-compile</goal>
</goals>
<configuration>
<sourceDirectory>${basedir}/R</sourceDirectory>
<dataDirectory>${basedir}/data</dataDirectory>
<defaultPackages>
<package>methods</package>
<package>stats</package>
<package>utils</package>
<package>grDevices</package>
<package>graphics</package>
<package>datasets</package>
</defaultPackages>
</configuration>
</execution>
<execution>
<id>renjin-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<timeoutInSeconds>30</timeoutInSeconds>
<testSourceDirectory>${basedir}/tests</testSourceDirectory>
<defaultPackages>
<package>methods</package>
<package>stats</package>
<package>utils</package>
<package>grDevices</package>
<package>graphics</package>
<package>datasets</package>
</defaultPackages>
</configuration>
</execution>
<execution>
<id>gnur-compile</id>
<phase>compile</phase>
<goals>
<goal>make-gnur-sources</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Put this POM file in the root of you package and do mvn package
to create a JAR file.
If you need more automation, then you will have to do this yourself using some kind of build system. And don't forget to add dependencies to the POM if your package requires them (tip: copy the POM snippets from packages.renjin.org).
来源:https://stackoverflow.com/questions/39333462/automated-porting-of-r-library-for-renjin