[Rd] is.loaded() and dyn.load()
Simone Giannerini
sgiannerini at gmail.com
Wed Apr 11 12:40:42 CEST 2007
Your aggressive tone would be inacceptable even if your comments were
relevant.
What's more they are not.
The point here is that under Windows it is very likely that fortran
compiled code is not being properly loaded unless g77 is used, and that
is.loaded() would trigger the dynamic loading. It is neither a matter of
underscores in variable names nor of fixed form f77.
see the example below
I attach the FORTRAN 77 fixed form source file tryme.f which has been
compiled with Compaq Visual Fortran 6.6c3
# df tryme.f -dll -LINK -RELEASE
then, under R
> dyn.load("tryme.dll");
try.me <- function(X){
S <- .Fortran("tryme",as.integer(X),S=as.integer(0))$S #
return(S)
}
> try.me(8)
Error in .Fortran("tryme", as.integer(X), S = as.integer(0)) :
Fortran symbol name "tryme" not in load table
> is.loaded("tryme")
[1] TRUE
> try.me(8)
[1] 9
The problem does not show up if g77 is used:
# g77 tryme.f -shared -s -otryme.dll
> dyn.load("tryme.dll");
> try.me(8)
[1] 9
The issue does not show up in my OpenSUSE 10.2 box with R patched compiled
with gfortran;
> dyn.load("tryme.dll");
>
> try.me <- function(X){
+ S <- .Fortran("tryme",as.integer(X),S=as.integer(0))$S
+ return(S)
+ }
>
> try.me(8)
[1] 9
> unlist(R.Version())
platform
"x86_64-unknown-linux-gnu"
arch
"x86_64"
os
"linux-gnu"
system
"x86_64, linux-gnu"
status
"Patched"
major
"2"
minor
"4.1"
year
"2007"
month
"03"
day
"20"
svn rev
"40858"
language
"R"
version.string
"R version 2.4.1 Patched (2007-03-20 r40858)"
All this regardless of the kind of Fortran language used and independently
from the presence of underscores in variable names.
Besided this IMHO it might be interesting to discuss in this list the issues
related to Fortran 90/95 and the use of different compilers in view of a
possible complete support from R also considered that
1. under Linux gfortan is now the default compiler for gcc>4.0.0
2. switching back to F77 might **not** be an option for many people.
My intention here was also to provide the community with some feedback on
this but it is hard to have a proper discussion
in these conditions.
Kind regards,
Simone Giannerini
On 4/5/07, Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:
>
> Did you read the comments under ?.Fortran about this? What you are doing
> is quite explicitly said not to be supported.
>
> gfortran is not a supported Fortran compiler for R for Windows 2.4.1.
> It behaves differently from the supported g77.
> The behaviour is adapted to the compiler used when configure is used, and
> on Windows that is what the maintainers used, not you are using. If you
> follow the advice not to use underscores in names you are much less likely
> to confuse yourself and produce portable code.
>
> On Thu, 5 Apr 2007, Simone Giannerini wrote:
>
> > 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 ************************************
> > dyn.load("try_it.dll");
> >
> >
> > try.it <- function(X){
> > N <- length(X);
> > S <- .Fortran("try_it_",as.double(X),as.integer(N),S=as.double(0))$S
> > return(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
> > is.loaded("try_it_")in
> > the file try_it.R does the trick but
> > is this behaviour expected?
> >
> > Thank you,
> >
> > Regards
> >
> > Simone
> >
> >> R.version
> > _
> > platform i386-pc-mingw32
> > arch i386
> > os mingw32
> > system i386, mingw32
> > status
> > 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)
> >
>
> --
> 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
>
--
______________________________________________________
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