Search code examples
rcompilationjit

R: How to enable JIT compiler via script, not environment?


I work on several R projects at the same time. One of them involves a simulation with a for-loop, which I hope to speed up by using a JIT-compiler. To do so, I added to the file Rcmd_environ in my R-directory/etc the lines following this recommendation.

R_COMPILE_PKGS=TRUE
R_ENABLE_JIT=3

Now I wonder, whether it is possible, to turn this on and off via a script. This way, I wouldn't have JIT-compilation in my other projects. Any ideas?


Solution

  • You can load the compiler library and then set the JIT level via calling the 'enableJIT` function.

    For e.g. you can do

    require(compiler)
    enableJIT(3)
    

    to get full JIT compilation.