Skip to content

Compiling R code to native code?

4 messages · Gregory Propf, Jeff Newmiller, Ben Bolker +1 more

#
Nope. Most users get speed by using vectorized calculations. If you have already identified how to get correct answers, the next step is something like Rcpp or linking to a shared library written in your language of choice.

But seriously, vectorizing is enough for most applications, and making sure the answer is right doesn't usually require compiled code.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.
Gregory Propf <gregorypropf at yahoo.com> wrote:

            
#
Jeff Newmiller <jdnewmil <at> dcn.davis.ca.us> writes:
Note that there is a fairly recently introduced byte-compiler
for R (library("compiler"); ?compile).  There's also
http://www.milbo.users.sonic.net/ra/ , which looks a little out
of date by now (last release August 2011), but it might be
worht comparing.  As Jeff said, though, there is usually room
for lots of speed improvement via vectorizing (or using add-on
packages such as data.table ).  I *believe* typical speed-ups
from the built-in compiler are on the order of three-fold.
Porting to compiled languages (most popularly via Rcpp) can
give much higher speed-ups.  For more information we'd really
need to know what you are trying to do.  You might try searching
Stack Overflow for "[r] speed up" ...
#
Facts:

1. R does not by default compile bytecode. It uses a read-parse-eval
cycle as described in the R Language Manual.

2. However, as of 2.14.0 (anyway) there is a "compiler" package that
is shipped as part of the standard distribution. Written by Luke
Tierney and his graduate student minions, it is described here:
http://www.divms.uiowa.edu/~luke/R/compiler/compiler.pdf

As usual, it can result in considerable speedup, though vectorization
is still a good strategy when possible.

To be clear, Jeff's original reply is correct -- R is interpreted, not compiled.

Cheers,
Bert

On Sat, Jan 28, 2012 at 5:01 PM, Jeff Newmiller
<jdnewmil at dcn.davis.ca.us> wrote: