[Rd] is.loaded() and dyn.load()

Simone Giannerini sgiannerini at gmail.com
Thu Apr 5 16:45:12 CEST 2007

Dear all,

I am puzzled at the behaviour of is.loaded() when a dyn.load() call to a a
FORTRAN shared library is included in a file to be sourced.
A reproducible example is the following:

1. the attached fortran subroutine try_it.f90 performs a summation of the
elements of a REAL*8 vector
compile with

gfortran try_it.f90 -shared -s -otry_it.dll

2. create a file to be sourced (see the attached try_it.R) containing the
following commands:

BEGIN try_it.R ************************************

try.it <- function(X){
    N <- length(X);
    S <- .Fortran("try_it_",as.double(X),as.integer(N),S=as.double(0))$S
END try_it.R ************************************

3. Switch to R

> source("try_it.R")
> try.it(1:10)
Error in .Fortran("try_it_", as.double(X), as.integer(N), S = as.double(0))
        Fortran symbol name "try_it_" not in load table
> is.loaded("try_it_")
[1] TRUE
> try.it(1:10)
[1] 55
it looks like is.loaded() triggers the loading, inserting
the file try_it.R does the trick but
is this behaviour expected?

Thank you,



> R.version
platform       i386-pc-mingw32
arch           i386
os             mingw32
system         i386, mingw32
major          2
minor          4.1
year           2006
month          12
day            18
svn rev        40228
language       R
version.string R version 2.4.1 (2006-12-18)

Simone Giannerini
Dipartimento di Scienze Statistiche "Paolo Fortunati"
Universita' di Bologna
Via delle belle arti 41 - 40126  Bologna,  ITALY
Tel: +39 051 2098262  Fax: +39 051 232153

More information about the R-devel mailing list