Search code examples
javarpackagedevtoolsrjava

how to include a java dependency for an R package


I have an R package that interacts with a java dependency (jar file) via the rJava package. I have no issues making things work when developing, but I don't know how to get the package installer to keep the jars with the installation in some sort of java src directory (e.g., file.path(.libPaths()[1], "mypackage", "java"). Is this possible without needing to write custom configuration files?

I am attempting to install using devtools::install_git. My source data is organized like most other R packages (I'm using the other features of devtools as well) except that I have an additional subdirectory java where my java dependencies are stashed.

Thanks


Solution

  • Keep the jar files in /inst/java and have something like the following in zzz.R

    .onLoad <- function(libname, pkgname) {
      .jpackage(name = pkgname, jars = "*")
    }