From: Duncan Murdoch <murdoch_at_stats.uwo.ca>

Date: Tue 07 Jun 2005 - 01:26:41 EST

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Jun 07 01:57:03 2005

Date: Tue 07 Jun 2005 - 01:26:41 EST

On 6/6/2005 9:52 AM, Rolf Turner wrote:

> I wish to pass a vector ``y'', some of whose entries are NAs to a

*> fortran subroutine which I am dynamically loading and calling by
**> means of .Fortran(). The subroutine runs through the vector entry by
**> entry; obviously I want to have it do one thing if y[i] is present
**> and a different thing if it is missing.
**>
**> The way I am thinking of proceeding is along the xlines of:
**>
**> ymiss <- is.na(y)
**> rslt <- .Fortran(
**> "foo",
**> NAOK=TRUE,
**> as.double(y),
**> as.logical(ymiss),
**> etc,
**> etc
**> )
**>
**> and inside ``foo'' have a logical branch based on the value of
**> xmiss(i).
**>
**> Questions:
**>
**> (1) Is there a sexier way to proceed? E.g. is it possible
**> within (g77) fortran to detect the fact that y(i) is/was an
**> NA (or not) and make the nature of y(i) the basis of an
**> if-statement?
*

In C you can use the macros

ISNA(x) True for R’s NA only

ISNAN(x) True for R’s NA and IEEE NaN

R_FINITE(x) False for Inf, -Inf, NA, NaN

where the R function is.na() is closest to ISNAN(), I think. There's no supplied way to do these things in Fortran, but presumably you could call a C function which did one of these tests.

> (2) Are there any lurking pitfalls in the use of the NAOK=TRUE

*> argument?
*

I think the way you did it looks perfectly safe. Following my advice above will be a little trickier, because some other user of your code might use a different Fortran compiler, and it might handle C functions differently.

> (3) Is there an entirely different and better way to proceed?

I'd do it your way if I was using Fortran.

Duncan Murdoch

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Jun 07 01:57:03 2005

*
This archive was generated by hypermail 2.1.8
: Fri 03 Mar 2006 - 03:32:23 EST
*