Implements a bytecode compiler for 'R' in 'C', targeting functional parity with the base 'compiler' package, while focusing on better performance. The architecture mostly mirrors the original 'GNU-R' compiler as described in < https://homepage.cs.uiowa.edu/~luke/R/compiler/compiler.pdf>.
crbcc is an R package that compiles R code to bytecode using a C implementation.
It is intended as a fast, drop-in alternative to the base compiler package, for cases in which
a reduced compilation time could be beneficial, eg. in research.
However using crbcc for minor performance improvements inside R's JIT pipeline is also possible.
This project was developed as part of a bachelor's thesis at FIT CTU.
When possible, crbcc mirrors the architecture and logic used in the original GNU-R compiler package by Luke Tierney. The original compiler Noweb document is available at https://homepage.cs.uiowa.edu/~luke/R/compiler/compiler.pdf, or distributed as an R base package, available under the GPL-2 license. Most documentation provided in the document is relevant to crbcc as well.
cmpfun tested on a corpus consisting of around 339,000 lines of codecrbcc::cmpfun()crbcc::compile()crbcc::cmpfile()crbcc::loadcmp()R CMD INSTALL .
or with the provided Make target:
make install
library(crbcc)
f <- function(x) {
y <- x + 1
y * 2
}
cf <- cmpfun(f, options = list(optimize = 2))
cf(10)
library(crbcc)
cmpfile("script.R", "script.Rc")
loadcmp("script.Rc", envir = .GlobalEnv)
The compiler accepts options as a named list:
optimize (integer): optimization level (default 2)suppressAll (logical): suppress warnings (default TRUE)suppressNoSuperAssignVar (logical): suppress missing super-assignment variable warningssuppressUndefined (logical or character):
TRUE: suppress all undefined variable/function warningsFALSE: suppress nonecharacter(): suppress specific namesExample:
opts <- list(
optimize = 2,
suppressAll = FALSE,
suppressUndefined = c("pi", "letters")
)
cf <- cmpfun(function(x) x + pi, options = opts)
Contributions are welcome.
R CMD check .
compiler package.cmpfile() currently does not support a functional verbose mode (the argument exists but is not implemented).