Package news
With the revamped GCC-Bridge plugin we have been working to bring more CRAN and Bioconductor packages to Renjin. This approach results in pure JVM bytecode that can be safely used in multi-threaded and sandboxed environments.
bitops
The bitops package, which provides efficient bitwise operations on integer vectors, is a good example of how this approach can be successful. With the latest version of Renjin, the bitops package's comprehensive test suite is 100% successful on Renjin. Click here to visit the package page on renjin.org.
DBI
However, some packages warrant a different approach. Last year, we wrote about how we created a drop-in replacement for the DBI package and many related packages such as RPostgreSQL, RMySQL, MonetDB.R, ROracle and RSQLite. Instead of porting the DBI package to Renjin, we chose to replace the package internals with calls to JDBC, a standard Java library for accessing databases.
rjson
Another example is the rjson package for which we used Google's Gson library in Java. In fact, this package is a great source on how to expose Java libraries to your R code in Renjin. For example, the package's NAMESPACE file uses the Renjin-specific importClass directive:
importClass(org.renjin.cran.rjson.JsonWritingVisitor)
importClass(org.renjin.cran.rjson.JsonParser)
export(toJSON, newJSONParser, fromJSON)
The package includes two Java classes called JsonWritingVisitor and JsonParser which are wrapped by a small R script to expose their functionality to your R code. For example, the toJSON() R function is simply defined as
toJSON <- function( x, method = "C" ) {
JsonWritingVisitor$toJson(x)
}
where JsonWritingVisitor$toJson(x) executes the toJson method of the JsonWritingVisitor class.
Visit the source code of the package at https://github.com/bedatadriven/renjin-json or click here to visit the package page on renjin.org. You can also visit the chapter on importing Java classes in your R code in our documentation online.
|