[R] making package interface with FORTRAN under windows

cls59 chuck at sharpsteen.net
Sun Sep 13 21:11:44 CEST 2009




Carrie Li wrote:
> 
> Dear r-help group,
> 
>   I am creating a package that has some FORTRAN code under windows. I have
> read through "Writing R Extension" but still not so clear about the steps.
> 
> Before R CMD build, how can I create a dynamic library and later in my R
> function using dyn.load ("xxx.dll") ?
> If I already have a .dll file, can I build the package with the dll file
> directly ?
> Does any one have any reference with the steps easier to follow ?
> 
> Many thanks!
> 
> Carrie
> 
> 


The easiest way to approach this is to leave the creation of the .dll to R.
This is done by storing your fortran source code inside a folder named 'src'
inside the R package. For example, say you have a package like the
following:

myPackage/
  DESCRIPTION
  R/
  man/
  src/

Placing a Fortran file, say mySubroutine.f90 inside the src/ folder will
cause R to automatically create and install myPackage.dll when the package
is built. The final step is to ensure R loads the dll when the library is
loaded. This is done by adding a file called zzz.R to the R/ folder which
contains the following function:

.onLoad <-
function( libname, pkgname ){

  # You can put other package startup stuff in here as well.

  library.dynam( pkgname, pkgname, libname )

}

Now the rest of your package functions will be able to access the Fortran
routines in the dll through calls to .Fortran.

-Charlie

-----
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: http://www.nabble.com/making-package-interface-with-FORTRAN-under-windows-tp25425236p25426155.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list