为Renjin自动移植R库 [英] Automated porting of R library for Renjin

查看:90
本文介绍了为Renjin自动移植R库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些本地R库,我想将其包含在renjin Java应用程序中.有些库完全用R编写,有些库具有C ++依赖关系,有些库具有S4类.理想情况下,我不想维护每个库的两个副本.

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.

我想知道是否有任何自动化的方法来获取本地R库(或其源代码)并生成与Renjin兼容的版本?

I am wondering if there is any automated way to take a local R library(or its sources) and generate a Renjin compatible version?

推荐答案

packages.renjin.org中列出的所有CRAN和Bioconductor软件包被编译为Java字节码(包括C,C ++和Fortran源代码),并通过全自动构建系统从原始源代码打包为JAR.

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.

Renjin文档包含有关创建说明. 包,但对于只有R代码的包,与GNU R包的区别仅在于建议的(因此是可选的)目录布局.

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.

要构建遵循GNU R的目录结构约定的R包,必须仅添加一个Maven POM文件,其中应包含有关R源文件位置的信息.例如(请注意软件包名称和版本的占位符):

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>

将此POM文件放入包的根目录,然后执行mvn package创建一个JAR文件.

Put this POM file in the root of you package and do mvn package to create a JAR file.

如果您需要更多的自动化,那么您将必须使用某种构建系统自行完成此操作.而且,如果您的程序包需要依赖项,请不要忘记将依赖项添加到POM中(提示:从 packages.renjin.org复制POM片段. ).

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).

这篇关于为Renjin自动移植R库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆