R/C Code

From QERM Wiki
Revision as of 18:29, 8 July 2009 by Chloe (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search



Sometimes R users need to encounter C, for example, to maintain an R package, or to speed up existing functions. It is fairly straightforward to run C code from within R. Pdf10.png Here is how, with some easy-to-follow examples. More detailed information can be found in Writing R Extensions.

Tools needed


Everything should be already installed. You may need to install developer tools on Mac if they're not already there.


Install Rtools to get the necessary toold to compile code and build packages for R. Be careful if you already have Cygwin installed.

Simple example

From the command line:

R CMD SHLIB foo.c 

(you may need the whole path to R if it's not in your path)

To load what you just built to use in R:

file.path(path, paste("foo", .Platform$dynlib.ext, sep=""))
Personal tools