[R] C code generators

adrian at maths.uwa.edu.au adrian at maths.uwa.edu.au
Wed Aug 22 04:20:32 CEST 2007


Dear R-helpers

Are there any established R packages that include a C code generator -- 
that generates new C language files and compiles them?

To be precise what I'm looking for is a process that takes text input in
some format (it might be pseudocode, fragments of C code, etc) and creates
a valid C language source file that can be compiled by R CMD COMPILE.
Ideally the procedure should also cause the C code to be compiled and
dynamically loaded.

To give a trivial example, suppose I want to be able to perform image
filtering operations on matrices. All filters have the same structure:
each position [i,j] in the matrix is visited in a double loop; a
calculation (depending on the filter) is performed using the value at
[i,j] and also the values at neighbouring positions [i+1,j] , [i+1,j+1]
etc; the result is written to the output matrix at the position [i,j]. The
C code for the loop is always the same; only a few lines of code that
perform the filter calculation will change. I would like a procedure that
accepts a text file containing just a few lines of C code or pseudocode,
and inserts these lines into the appropriate place in the loop, producing
a valid C language routine which can then be compiled by R CMD COMPILE and
dynamically loaded.

(Of course, it can get more complicated than just inserting a single text
fragment!)

I once implemented such a feature in an image processing package, so I
know it's not hard. Before dusting off this ancient code I would like to
learn whether there's an R package or other open source program that
already does it.

Any pointers would be welcome

thanks
Adrian Baddeley



More information about the R-help mailing list