[R] Fortran

Liaw, Andy andy_liaw at merck.com
Sat Oct 26 04:13:58 CEST 2002


Which manual did you read?  I thought the "Writing R Extensions" manual has
quite a few examples!

Try the following fortran (say "square.f"):

      subroutine square(n, x, x2)
      integer i,n
      double precision x(n), x2(n)
      do i = 1, n
         x2(i) = x(i) * x(i)
      end do
      end

Then compile with `R CMD SHLIB square.f' which produces squared.so on *nix.
(On Windoze, you'd do `Rcmd SHLIB sqaure.f', which produces squared.dll,
assuming you've got the right tools installed.)  You then start up R, and do

  dyn.load("square.so")  ## Or dyn.load("square.dll") on Windoze
  x <- 1:10
  .Fortran("square", as.integer(length(x)), as.double(x),
as.double(numeric(length(x)))


Andy 

-----Original Message-----
From: Stephen Elijah [mailto:ilievs at lovell.econ.queensu.ca]
Sent: Friday, October 25, 2002 8:24 PM
To: r-help at stat.math.ethz.ch
Subject: [R] Fortran


Hello everybody,
Could someone please send me a very simple example using Fortran from
R? Say pass a value to an executable and get the result in R. Actually it
seems it may be possible to call an *.f file ?? or I am wrong again?
The manual is very terse on the subject.
Thank you very much

Stephen Elijah

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._

------------------------------------------------------------------------------
Notice: This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (Whitehouse Station, New Jersey, USA) that may be confidential, proprietary copyrighted and/or legally privileged, and is intended solely for the use of the individual or entity named on this message.  If you are not the intended recipient, and have received this message in error, please immediately return this by e-mail and then delete it.

==============================================================================

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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