[R] .C, .Fortran and DUP

gb gb at stat.umu.se
Fri Jul 7 10:44:02 CEST 2000

In an  R  function, I have a huge matrix  x, which I update
several times. For some reasons I want to do the updating
with a call to  .Fortran  (simpler than  .C  with matrices,
it seems). This is my (simplified) code:

In the  R  function:
   x <- matrix(0, nrow = n.row, ncol = n.col)
   storage.mode(x) <- "double"
   for (i in reps)
      stuff <- ...
               DUP = FALSE)

The FORTRAN side:
      subroutine updatex(stuff, nrow, ncol, x)
      implicit none
      integer nrow, ncol             
      double precision stuff(ncol), x(nrow, ncol)
      (...updating x...)

I use  DUP = FALSE  to avoid copying the huge matrix  x,
but if I read  ?.C  correctly, this is *dangerous* 
because of the repeated calls to  .Fortran.
However, it works fine for me (so far).

Question: *Is* this dangerous? I have the option of writing
the whole loop in Fortran, of course, but I want to avoid that
if possible.

 Göran Broström                      tel: +46 90 786 5223
 Department of Statistics            fax: +46 90 786 6614
 Umeå University
 SE-90187 Umeå, Sweden             e-mail: gb at stat.umu.se

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