Joyful. I'm adapting a FORTRAN 77 package for use with R. Pretty straightforward. Except for a glitch it took me some time to figure out. This existing package has subroutines which have parameters called "NA". So, I called subroutines like bnodes <- function(n, lst, lptr, lend, nodes, nb, na, nt) { ensure.all.numeric(list(n, lst, lptr, lend, nodes, nb, n.a, nt), "all arguments to -bnodes- must be numeric") out <- .Fortran("bnodes", N=as.integer(n), LIST=as.integer(lst), LPTR=as.integer(lptr), LEND=as.integer(lend), NODES=as.integer(nodes), NB=as.integer(nb), NA=as.integer(na), NT=as.integer(nt)) return(out[5:8]) } I had called routines successfully before, so I couldn't figure out what was wrong. By elimination, I discovered that the parameter pass NA=as.integer(na) was to blame. So, thinking the right-hand-side (R's world) was the problem, even if "na" wasn't recognized as "not available", I changed to: bnodes <- function(n, lst, lptr, lend, nodes, nb, n.a, nt) { ensure.all.numeric(list(n, lst, lptr, lend, nodes, nb, n.a, nt), "all arguments to -bnodes- must be numeric") out <- .Fortran("bnodes", N=as.integer(n), LIST=as.integer(lst), LPTR=as.integer(lptr), LEND=as.integer(lend), NODES=as.integer(nodes), NB=as.integer(nb), NA=as.integer(n.a), NT=as.integer(nt)) return(out[5:8]) } No win. I would only be happy if I used bnodes <- function(n, lst, lptr, lend, nodes, nb, n.a, nt) { ensure.all.numeric(list(n, lst, lptr, lend, nodes, nb, n.a, nt), "all arguments to -bnodes- must be numeric") out <- .Fortran("bnodes", N=as.integer(n), LIST=as.integer(lst), LPTR=as.integer(lptr), LEND=as.integer(lend), NODES=as.integer(nodes), NB=as.integer(nb), NAA=as.integer(n.a), NT=as.integer(nt)) return(out[5:8]) } and had to actually change the FORTRAN code to comply. Sounds to me like there's a little room for improvement here. Should be documented anyway.
Galkowski, Jan wrote:> Joyful. > > I'm adapting a FORTRAN 77 package for use with R. Pretty > straightforward. > > Except for a glitch it took me some time to figure out. This existing > package has subroutines which have parameters called "NA". So, I called > subroutines like > > bnodes <- function(n, lst, lptr, lend, nodes, nb, na, nt) > { > ensure.all.numeric(list(n, lst, lptr, lend, nodes, nb, n.a, nt), > "all arguments to -bnodes- must be numeric") > out <- .Fortran("bnodes", N=as.integer(n), LIST=as.integer(lst), > LPTR=as.integer(lptr), LEND=as.integer(lend), > NODES=as.integer(nodes), > NB=as.integer(nb), NA=as.integer(na), > NT=as.integer(nt)) > return(out[5:8]) > } > > I had called routines successfully before, so I couldn't figure out what > was wrong. By elimination, I discovered that the parameter pass > > NA=as.integer(na) > > was to blame. So, thinking the right-hand-side (R's world) was the > problem, even if "na" wasn't recognized as "not available", I changed > to: > > bnodes <- function(n, lst, lptr, lend, nodes, nb, n.a, nt) > { > ensure.all.numeric(list(n, lst, lptr, lend, nodes, nb, n.a, nt), > "all arguments to -bnodes- must be numeric") > out <- .Fortran("bnodes", N=as.integer(n), LIST=as.integer(lst), > LPTR=as.integer(lptr), LEND=as.integer(lend), > NODES=as.integer(nodes), > NB=as.integer(nb), NA=as.integer(n.a), > NT=as.integer(nt)) > return(out[5:8]) > } > > No win. I would only be happy if I used > > bnodes <- function(n, lst, lptr, lend, nodes, nb, n.a, nt) > { > ensure.all.numeric(list(n, lst, lptr, lend, nodes, nb, n.a, nt), > "all arguments to -bnodes- must be numeric") > out <- .Fortran("bnodes", N=as.integer(n), LIST=as.integer(lst), > LPTR=as.integer(lptr), LEND=as.integer(lend), > NODES=as.integer(nodes), > NB=as.integer(nb), NAA=as.integer(n.a), > NT=as.integer(nt)) > return(out[5:8]) > } > > and had to actually change the FORTRAN code to comply. > > Sounds to me like there's a little room for improvement here. Should be > documented anyway. >Do the argument names even get used on the Fortran side?? AFAIK, it only matters for labeling the result. Anyways, this has nothing to do with "not available", a name like PACK would get you equally confused. You are being bitten by partial argument matching: NA matches NAOK. One workaround is to add NAOK=FALSE explicitly to the call. Or just use lowercase names. -- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Jan Galkowski wrote> I'm adapting a FORTRAN 77 package for use with R. Pretty > straightforward. > > Except for a glitch it took me some time to figure out. This existing > package has subroutines which have parameters called "NA". So, I called > subroutines like > > bnodes <- function(n, lst, lptr, lend, nodes, nb, na, nt) > { > ensure.all.numeric(list(n, lst, lptr, lend, nodes, nb, n.a, nt), > "all arguments to -bnodes- must be numeric") > out <- .Fortran("bnodes", N=as.integer(n), LIST=as.integer(lst), > LPTR=as.integer(lptr), LEND=as.integer(lend), > NODES=as.integer(nodes), > NB=as.integer(nb), NA=as.integer(na), > NT=as.integer(nt)) > return(out[5:8]) > } > > I had called routines successfully before, so I couldn't figure out what > was wrong. By elimination, I discovered that the parameter pass > > NA=as.integer(na) > > was to blame.The issue here is simply that NA is a reserved word in R. (Had we been given the actual error message this would have been obvious.) Peter Dalgaard suggested:> Anyways, this has nothing to do with "not available", a name like PACK > would get you equally confused. You are being bitten by partial argument > matching: NA matches NAOK. One workaround is to add NAOK=FALSE > explicitly to the call. Or just use lowercase names.But partial matching is not done following ..., and NAOK and PACKAGE do follow ... in the argument list of .Fortran, .C etc. I checked, and NAO and PACK both do work. -- 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