Skip to content

Samples of external code with various compilers?

5 messages · Brian Ripley, Duncan Murdoch

#
R can run external code in C, C++, Fortran, Delphi, etc., but the R
extensions manual only gives limited documentation for anything but C
and C++.  It would be useful to have a collection of sample code
showing how to dyn.load functions written in other languages, if
necessary for a variety of different compilers, in case that makes a
difference.

Does such a collection already exist?  If not, would it be better to
put it into the R extensions manual as a series of appendices, or just
have a web page about it?

I'd volunteer to maintain the web page to hold the samples.

Duncan Murdoch
#
On Sun, 1 Dec 2002, Duncan Murdoch wrote:

            
I think there is information and lots of examples already for Fortran. I
am not sure what more there is to say in `Writing R Extensions'. We could
point at an example in the R code I you think it would be helpful.  But
I'm puzzled here as to what you find lacking. (Fortran is supported both
via .Fortran and by some of the functions described in the section on the
R API.)
Base R has only interfaces for C and Fortran (and that via C-style
linkage): SJava adds .Java.  So is the issue how to write in other
languages to use a C interface?  `how to dyn.load functions' is easy: you
just create an appropriate compiled object, a shared library, a DLL or (on
MacOS X as I understand it) a module.  The issues seem to be to export the
symbols correctly, and even more to import ones from R correctly,

I will be interested to hear if there are any other (than Java) candidate
languages that are widely available.  Delphi as I understand it is
Windows-only (and the related Kylix is Linux-only?).  Information on using
Delphi would be very helpful in the R for Windows documentation, but you
are one of the experts there.

Brian
#
On Mon, 2 Dec 2002 08:07:19 +0000 (GMT), you wrote in message
<Pine.LNX.4.31.0212020753570.1625-100000@gannet.stats>:
I was thinking of two additions:

 1.  Rewriting the samples in sections 4.2 and/or 4.5 in Fortran,
Delphi, etc.  I might make them a little more elaborate, e.g. showing
how to return a character string.

 2.  Write up the details of how to do it in various specific
compilers.  For example, if you're using Microsoft Visual Fortran, how
do you create a DLL, how do you set the exported entry points, what
bugs do you need to work around.
Yes, that's the main issue.  There are also issues even with C:  if
you're using some compiler other than gcc, you probably won't compile
using R SHLIB, so what do you need to do?

Duncan
#
On Mon, 2 Dec 2002, Duncan Murdoch wrote:

            
(Except the last is non-portable for Fortran).  Contributions welcome, of
course.
I think it is only an issue on Windows.  That needs to go in
readme.packages: some is already there.
You can: I do it all the time.  If you use use the same compilers to build
R and its extensions, it just works.

Brian
#
On Mon, 2 Dec 2002 16:08:12 +0000 (GMT), Brian Ripley wrote in message
<Pine.LNX.4.31.0212021606210.10423-100000@gannet.stats>:
But that's the point:  the portable things belong in the R Extensions
manual, but the non-portable things are still useful to people.
Yes, that file as lots of the type of information I was thinking of.
I had forgotten about it; it should probably be mentioned in (the
Windows version of) the dyn.load help file.

Duncan Murdoch