[R] Missing values in argument of .Fortran.

Rolf Turner rolf at math.unb.ca
Mon Jun 6 15:52:18 CEST 2005


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?

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

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

TIA.

			cheers,

				Rolf Turner
				rolf at math.unb.ca

P. S. I'm running R 2.0.1 under (Red Hat) Linux.  (Sigh.  Yes I must
get around to upgrading real soon now.)

				R. T.




More information about the R-help mailing list