On 8/21/2007 10:20 PM, adrian at maths.uwa.edu.au wrote:> Dear R-helpers
>
> Are there any established R packages that include a C code generator --
> that generates new C language files and compiles them?
Oleg Sklyar's inline package does that. It takes input in the form of a
fragment of C (or C++, Fortran, etc.), completes the source code,
compiles it, loads it, and creates an R function to call it. See the
?cfunction man page for examples.
I wouldn't recommend this for extensive use: you're better off putting
your own code in a package instead. But it's good for quick tests, or
writing the first version of the code that goes in the package.
> 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.
As a matter of fact, one of Oleg's examples is an image filter.
Duncan Murdoch
>
> (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
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.