我想在我的人人Java应用程序中包含一些本地R库。一些库完全用R编写,一些库有C ++依赖,一些库有S4类。理想情况下,我不想保留每个库的两个副本。
我想知道是否有任何自动方式来获取本地R库(或其源代码)并生成Renjin兼容版本?
答案 0 :(得分:2)
packages.renjin.org中列出的所有CRAN和Bioconductor程序包都编译为Java字节码(包括C,C ++和Fortran源),并通过完全自动化的构建系统从原始源打包到JAR中。
Renjin文档包含instructions为Renjin创建包,但对于只有R代码的包,与GNU R包的区别仅在于建议(因此是可选的)目录布局。
要根据GNU R的目录结构约定构建自己的R包,必须只添加一个Maven POM文件,其中包含有关R源文件位置的信息。例如(注意包名称和版本的占位符):
<?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>
将此POM文件放在您的程序包的根目录中并执行mvn package
以创建JAR文件。
如果您需要更多自动化,那么您必须自己使用某种构建系统来完成此操作。如果您的包需要它们,请不要忘记向POM添加依赖项(提示:从packages.renjin.org复制POM片段)。