[R] the woes of NA
Professor Brian Ripley
ripley at stats.ox.ac.uk
Tue Jan 8 14:44:39 CET 2008
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
More information about the R-help
mailing list