The commonsMath package provides access to the Apache Commons Mathematics Library. It can can accessed via the:
We demonstrate below how to use it in:
library("rscala")
scala("commonsMath")
s <- s$.new_org.apache.commons.math3.random.RandomDataGenerator()
rng1 <-$reSeed(7342L)
rng1$nextGaussian(0,1) rng1
library("rJava")
.jinit(Sys.glob(file.path(system.file(package="commonsMath"), "java", "*.jar")))
.jnew("org.apache.commons.math3.random.RandomDataGenerator")
rng2 <-$reSeed(.jlong(7342L))
rng2$nextGaussian(0,1) rng2
The DESCRIPTION
should have Imports: rscala, commonsMath
.
The NAMESPACE
should have import(rscala)
.
Define an .onLoad
function like the following:
function(libname, pkgname) {
.onLoad <- scala("commonsMath")
s <-assign("s", s, envir = parent.env(environment()))
}
Package functions can then assess classes and methods from the commonsMath package, e.g.:
function() {
rstdnorm <- s$.new_org.apache.commons.math3.random.RandomDataGenerator()
rng1 <-$nextGaussian(0.0,1.0)
rng1 }
The DESCRIPTION
should have Imports: rJava, commonsMath
.
The NAMESPACE
should first have import(rscala)
and then have import(commonsMath)
.
Define an .onLoad
function like the following:
function(libname, pkgname) {
.onLoad <-.jpackage(pkgname, lib.loc=libname)
}
Package functions can then assess classes and methods from the commonsMath package, e.g.:
function() {
rstdnorm <- .jnew("org.apache.commons.math3.random.RandomDataGenerator")
rng2 <-$nextGaussian(0,1)
rng2 }