[R] Strange behavior using .Fortran
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Fri Jul 16 12:35:50 CEST 1999
"Uli Flenker; Raum 704" <uli at biochem.dshs-koeln.de> writes:
> Hello everybody,
>
> I observed some strange behavior of R (0.64.1/Linux 2.0.25) when trying
> to use FORTRAN-libraries.
>
> I downloaded "ALGORITHM AS 304" from StatLib. All I changed at
> the code, was to substitute "REAL"-routines by "DOUBLE PRECISION".
>
....
> Here is the prototype of R-code that I used ...
>
> > dyn.load("/path-to-lib/rtest.o")
>
> > fisher.ts.test<-function(x,y){
>
> nx<-length(x)
> ny<-length(y)
>
>
> ftr.out<-..Fortran("fisher",
??
> as.real(x),
> as.integer(nx),
> as.real(y),
> as.integer(ny),
> as.integer(0),
> as.integer(0),
> as.real(0.0),
> as.integer(0))
>
> return(ftr.out)
> }
>
>
> Loading the code was no problem. Now, here is what I obtained when using
> it:
>
> > a<-c(18,19,25)
> > b<-c(20,29,29,30,31,31,31)
>
> > fisher.ts.test(a,b)
> [[1]]
> [1] 18 19 25
>
> [[2]]
> [1] 3
>
> [[3]]
> [1] 20 29 29 30 31 31 31
...
> ... which are the correct results.
>
>
> But invoking the thing exchanging "a" and "b" gives the following strange
> things ...
>
> > fisher.ts.test(b,a)
> [[1]]
> [1] 31 31 31 30 31 31 31
...
>
> Furthermore ...
>
> > x<-round(rnorm(3,10),2)
> > y<-round(rnorm(7,5),2)
> > fisher.ts.test(x,y)
> Process R segmentation fault at Thu Jul 15 19:08:01 1999
Hmm... I can't offhand spot any obvious blunders. Are you sure you got
*all* reals converted to double in the Fortran routines? If you have
data that reliably causes segfault, try running it with R -d gdb (use
-g for the compilation) to get the exact line where it crashes. And,
btw, eliminate optimizer errors by compiling without -O.
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list