4. Using Renjin as an R Package

Though Renjin’s ultimate goal is to be a complete, drop-in replacement for GNU R, in some cases you may want to run only part of your existing R code with Renjin, from within GNU R.

For this use case, you can load Renjin as a package and evaluate performance-sensitive sections of your code, without having to rewrite the R code.

4.1. Prerequisites

You must have Java 7 installed or higher. For best performance, we recommend using the latest version of Oracle or OpenJDK 8. The rJava package is also required, but should be installed automatically.

4.2. Installation


4.3. Usage


bigsum <- function(n) {
  sum <- 0
  for(i in seq(from = 1, to = n)) {
    sum <- sum + i
bigsumc <- compiler::cmpfun(bigsum) # GNU R's byte code compiler