[R] Call a Fortran subroutine with R: R crashes

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Aug 19 07:40:18 CEST 2008


On Mon, 18 Aug 2008, Zornitsa Luleva wrote:

> Hello,
>
> I am trying to call a FORTRAN subroutine within R and something really
> strange happens:

Did you read the posting guide?  It suggests the R-devel list for 
questions about 'C, C++ etc', and Fortran is part of the 'etc'.

> I have a dll-library, that I load with dyn.load('mpbvv.dll'). I have checked
> the [Ordinal/Name Pointer] Table for the function within the library that I
> want to call - it is there (objdump - p mpbvv.dll).
>
> Then, I have written an R-wrapper to call the FORTRAN subroutine, which
> works fine. SInce I have 200 "points", at which I have to evaluate the
> function, I have to call it 200 times. It works about 100 times just fine
> and then R crashes. The values for which the function is evaluated are
> almost the same, there no sudden big differences.
>
> The only thing that is probably not really ok is that is.loaded('mpbvv.dll')
> returns FALSE.

Correctly: please do read the help before posting: ?is.loaded has

   symbol: a character string giving a symbol name.

not, note, a DLL name.

> But if I call getLoadedDLLs(), the library is loaded
>> getLoadedDLLs()
>                                                             Filename
> base                                                             base
> methods       C:/Programme/R/R-2.7.1/library/methods/libs/methods.dll
> grDevices C:/Programme/R/R-2.7.1/library/grDevices/libs/grDevices.dll
> stats             C:/Programme/R/R-2.7.1/library/stats/libs/stats.dll
> mpbvv                                            E:/Zoe/DA/mpbvv.dll
>          Dynamic.Lookup
> base                  FALSE
> methods            FALSE
> grDevices           FALSE
> stats                 FALSE
> mpbvv               TRUE
> I am loading four more libraries:
>
> library('actuar')
> library('bbmle')
> library('polynom')
> library('NORMT3')
>
> Could this be a problem?
>
> I don't have any idea why R crashes. Do you?

Most likely an error in your code.  Perhaps a mismatch (in type, in 
length) between what you pass .Fortran and what your code expects?
Without the reproducible example the posting guide asks for we can only 
guess.

> Thanks a lot for your advice in advance!
>
> Cheers,
> Zoe
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org 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.

PLEASE do.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list