[Rd] Creating a package which contains stand-alone C code

From: Rajen Shah <rds37_at_cam.ac.uk>
Date: Fri, 27 Apr 2012 14:54:45 +0100

I would like to create an R package which uses some C code, which in turn uses MPI. At the moment I'm only interested in creating this package for UNIX-like systems. The way I envisage this working is for the R package to contain an R function which uses the system call to run the C code as a separate process (passing to the C code the location of a file of data). The C code can then do what it needs to do with the data, send its output to a file, and when it has finished R can read the output from the file.

My question is, is it possible to create an R package which contains C code which can then be called by an R function in that package using the system call? The obstacles seem to be (i) compiling this C code in the right way for it to be called by system, and (ii) giving the R function responsible for calling the C code (via system) the location of the executable.

>From my understanding of the R extensions manual (i) can be solved
using careful configure script and Makevars file (though I don't know
the details), and (ii) would require me to provide an R script `src/install.libs.Rí, which would need to copy the executable to the right place, and modify my R function which uses the system call so it knows where to look for the executable.

link4"><a name="1039qlink4">ame="1039qlink4">name="1039qlink4"> name="1039qlink4"><a name="1039qlink4">The reason Iím interested in calling the C code in this peculiar way, rather than using the .C interface, for example, is that Iím worried about using MPI from within R. At least, my knowledge of both R and MPI is insufficient to be confident that calling MPI from within R will run smoothly. Also, this way I can debug the C program entirely on its own.

="1039qlink5"> name="1039qlink5"><a name="1039qlink5">ame="1039qlink5">name="1039qlink5"> name="1039qlink5"><a name="1039qlink5">I realise th<a name="1039qlink4">ere is an R package, Rmpi, which provides a wrapper for most of the MPI functions, but since all my code will be in C, it seems less sensible to make use of this, though I may be wrong.

Thank you for taking to the time to read this, and I very much appreciate any advice, (especially) even if it is to say that my proposed approach is entirely daft and I should do things completely differently. Also, if you know of any examples of packages which do what Iíve described above, Iíd be very glad to know (it seems Sjava does something like this?).

Best wishes,

Rajen Shah

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sat 28 Apr 2012 - 13:05:22 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 28 Apr 2012 - 14:40:51 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive