Does an R compiler to C/C++ exist?

22,540

Solution 1

A byte code compiler will be part of the R 2.13 release. By default it is not used in this release but it is available; I expect the 2.14 release will by default byte compile all base and recommended packages. The compiler::compile help page and the R Installation and Administration Manual give some more details.

Solution 2

I had forgotten about the Rice project, it has been a while. I think the operational term here is stated at the top of the project page: Last Updated 3/8/06.

And we all know R changes a lot. So I have only the standard few pointers for you:

  • Luke Tierney, who not only knows a lot about R internals but equally about byte compilers, has been working on such a project. Nothing ready yet, and it would still work in conjunction with the standard R engine.
  • Stephen Milborrow has the Ra extension to R that works with his just-in-time compiler package jit
  • my Introduction to High-Performance Computing with R tutorials (most recent tutorial slides from UseR! 2009) covers the profiling, compiling extentions, parallel computing with R, ... part, including Rcpp and and a bit about RInside.

In short: there is no way have what you desire specific ways to compile and deploy R code without installing R in advance. Sorry.

Edit/Update (April 2011): Luke's new compiler package will be part of R 2.13.0 (to be released April 2011) but not 'activated' by default which is expected for R 2.14.0 expected for October 2011.

Edit/Update (December 2011): Prof Tierney just release a massive 100+ page paper on the byte-code compiler.

Solution 3

Why do people get the fear when deploying R? I'm fairly sure I've seen this question before.

Installing R is a piece of cake (you don't actually say which OS you care about). For Windows its one .exe. file, run it, say "yes" a few times and its done. I suspect the installer exe probably has flags for unattended installation too.

Solution 4

You may check out the P compiler which implements a subset of R. Especially, lists, matrices, vectors etc. are implemented as well as lsfit, chol, svd, ...

You can download a free version at

www.ptechnologies.org

It speeds up computations substantially.

Best,

AS

Solution 5

I haven't used Garvin's package and don't know what is possible along those lines. However:

Typically people just write computationally intensive functions directly in C/C++/Fortran, after profiling to find the bottlenecks. See the RCpp interface or Calling C functions from R using .C and .Call for examples. The Scythe Statistical Library is also very nice for R users since the syntax/function names are similar.

Share:
22,540
Shane
Author by

Shane

Quantitative researcher focusing on statistics and machine learning methods in finance. Primarily use R, C++, Python, various databases (including OneTick and KDB), and LaTeX on a daily basis. Twitter: @statalgo Blog: http://www.statalgo.com (largely inactive) Former moderator on data analysis stack exchange site: http://stats.stackexchange.com/ Proposer of Quantitative Finance stack exchange site: http://area51.stackexchange.com/proposals/117/quantitative-finance?referrer=EZoOPpokWeo1

Updated on September 28, 2020

Comments

  • Shane
    Shane over 3 years

    I'm wondering about the best way to deploy R. Matlab has the "matlab compiler" (MCR). There has been discussion about something similar in the past for R that would compile R into C or C++. Does anyone have any experience with the R to C Compiler (RCC) that was developed by John Garvin at Rice?

    I've looked into it, and it seems to be the only project that worked on compiling R code into executable code. And as far as I can tell, it isn't still being used.

    [Edit 1:]: To be clear, I know that there are C and C++ (and Java, Python, etc.) interfaces to R (rJava, rcpp, Rpy, etc.). I'm wondering about specific ways to compile and deploy R code without installing R in advance.

    [Edit 2:]: John Mellor-Crummey tells me that they're still working on RCC and hope to make it available in 4 months or so (at the earliest). I'll update this further if I find anything else out.

  • Shane
    Shane over 14 years
    Thanks Dirk! Haven't checked out Luke's homepage recently. Your High-Performance Computing paper/tutorial is fantastic. I took the last updated date as meaning exactly what you say, but just wanted to check. :)
  • Shane
    Shane over 14 years
    Thanks, those are good links. I'm particularly focusing on the deployment process though, less than the performance issue.
  • Martin Morgan
    Martin Morgan about 13 years
    Are there hints / guidelines about when compilation will be effective? My most successful attempt so far has been a binary search, with 2x speedup; I'd been secretly hoping that S4 would become really fast, but no such luck?
  • Luke Tierney
    Luke Tierney about 13 years
    At this point large functions and loops will benefit. Calling compiled functions uses the same mechanism for now as calling interpreted ones, so things dominated by function call overhead will see little change. This will likely evolve over the next year or so.
  • Dirk Eddelbuettel
    Dirk Eddelbuettel about 13 years
    I blogged an example today which focuses on (simple, stupid, unrealistic) loops: dirk.eddelbuettel.com/blog/2011/04/… I am sure there will be more posts on this once R 2.13.0 is formally released tomorrow.
  • Iterator
    Iterator almost 13 years
    R is easy. Some packages and their dependencies are not, especially if these involve certain other languages. Java and Tcl/Tk come to mind.