[Rd] using a "third party" DLL in my package

Seija Sirkiä seija.sirkia at metla.fi
Thu May 14 13:59:27 CEST 2009

Hello all,

it seems my efforts in reading the manuals and help files aren't enough 
so here I am. The question is, how would I go about linking a 
pre-compiled DLL in to my package? I have previously successfully built 
packages with Fortran and C source code, but now I'd like to take this 
ready made DLL and call its routines from R.

My collegue was brave enough to simply try and put the DLL in src folder 
of the package and proceed with building and installing the same way as 
if it had been source code. And it works, on my computer and his. 
Clearly this isn't exactly portable, and while that's ok for the use we 
have in mind (we both work on Windows XP) I have a nagging feeling this 
is somehow criminal or unwise at least.

Why I want to do this might explain it a bit further but in fact the 
background contains another problem and I welcome anyone to give hints 
about that too.

So, we have some Fortran code from way back which deals with fitting 
taper curves for tree boles, and some other functions related to that. 
We wanted to make these available for use in R and I made a package with 
simple wrapper functions for the .Fortran calls, and built it with the 
help of the compiler in Rtools. All was fine until my collegue managed 
to bump in to a combination of parameters (tree species, height and 
breast height diameter) with which the computation freezes. We traced it 
to a certain very simple iteration in the Fortran code that finds the 
height at which the tree has a given diameter. I could give more details 
on that, but the point is that the very same computation goes through 
just fine when executed "fully" in Fortran, with the routines and an 
interface compiled with another Fortran compiler. And also when that 
compiler is used to make a DLL and that DLL is used within the R package 
in the way I described above.

In summary, what we seem to have here is a compiler dependent 
convergence problem. Possible solutions are to figure out what's wrong 
with the computation - and I've pretty much exhausted my skills on that 
- or to figure out how to use a working DLL, as was my first question.

Great big thanks in advance to anyone with advice!

Seija Sirkiä,
senior researcher (statistics), Finnish forestry research institute

More information about the R-devel mailing list