[R] the woes of NA

Galkowski, Jan jgalkows at akamai.com
Mon Dec 31 06:14:45 CET 2007


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.



More information about the R-help mailing list