Gilles GUILLOT
2004-Oct-22 10:16 UTC
[R] building an R package : where and how should my fortran library be loaded ?
Hi , I'm currently trying to make available a few fortran subroutines and R functions (which make interface to these subroutines), as an R package. I'm doing it under linux with R 1.9.0 (but hope to do it for windows too). I have trouble for loading my fortran code. Here are the steps involved : 1) In R: # Create tree for package # and include my R functions in it R> package.skeleton(name="Geneland", list=c("mcmcFmodel", "simFmodel", "rdiscr", "tessel.post"), path="/home/guillot/projets/flux/package/", force=T) # copy my fortran code in the tree R> system("cp /home/guillot/projets/flux/package/fortran/*.f /home/guillot/projets/flux/package/Geneland/src/") R> q() 2) In a Unix shell $ R CMD build Geneland $ R CMD check Geneland $ R CMD build Geneland $ R CMD INSTALL Geneland 3) Back to R R> library("Geneland") So far, it's OK, pure R functions work fine. But R functions calling some Fortran via .Fortran do not work, I get an error message like : Error in .Fortran("mcmc", ... Fortran function name not in load table If I make R> dyn.load("/usr/lib/R/library/Geneland/libs/Geneland.so") then it works . I was thinking that my Geneland.so was loaded automatically by the command library("Geneland") Obviously, it's not. Where and how should the library loaded ? Gilles _____________________________________________________________________ Gilles GUILLOT INRA -D??partement Math??matiques et Informatique Appliqu??es Unit?? de Mixte de Recherche INRA - INAPG - ENGREF Institut National Agronomique de Paris-Grignon 16 rue Claude Bernard 75231 Paris cedex 5 Aile Claude Bernard Niveau cours +3 ??tages tel : +33 (0)1 44 08 72 71 fax : +33 (0)1 44 08 16 66 http://www.inapg.fr/ens_rech/mathinfo/personnel/guillot/welcome.html ______________________________________________________________________ -- _____________________________________________________________________ Gilles GUILLOT INRA -D??partement Math??matiques et Informatique Appliqu??es Unit?? de Mixte de Recherche INRA - INAPG - ENGREF Institut National Agronomique de Paris-Grignon 16 rue Claude Bernard 75231 Paris cedex 5 Aile Claude Bernard Niveau cours +3 ??tages tel : +33 (0)1 44 08 72 71 fax : +33 (0)1 44 08 16 66 http://www.inapg.fr/ens_rech/mathinfo/personnel/guillot/welcome.html
Prof Brian Ripley
2004-Oct-22 10:42 UTC
[R] building an R package : where and how should my fortran library be loaded ?
On Fri, 22 Oct 2004, Gilles GUILLOT wrote:> I'm currently trying to make available > a few fortran subroutines and R functions > (which make interface to these subroutines), > as an R package. > I'm doing it under linux with R 1.9.0Please update, as few of us have such an old system in use.> (but hope to do it for windows too). > I have trouble for loading my fortran code.[...]> I was thinking that my Geneland.so was loaded automatically > by the command library("Geneland")`Thinking'? `Hoping', perhaps, but where did you read that?> Obviously, it's not. > Where and how should the library loaded ?By your R code, via library.dynam. A common `spell' is for package foo to include in foo/src/zzz.R .First.lib <- function(libpath, pkgname) library.dynam("foo", pkgname, libpath) and it described in `Writing R Extensions'. That also explains the different rules for packages with namespaces. -- 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