[R] NULL or NA for missing function arguments?

Hans-Peter gchappi at gmail.com
Mon Oct 16 19:51:59 CEST 2006


2006/10/16, Duncan Murdoch <murdoch at stats.uwo.ca>:
> As Gabor said, the third way is to give no default, but test missing()
> in the code.

I forgot this one, thank you. In my case it is probably not suited as
I just pass the arguments to a C (Pascal) function and do the checking
there.

[explanations snipped]
> So generally my advice would be:
> - Be consistent with similar existing functions.
> - Choose what you think will be convenient in current and predicted
> future versions of your function.

Ok, thank you. - Until now I always used NA but will (apart from your
advice) prefer NULL from now on. In C (Pascal) code NULL is also
easier to check than NA*

Thanks again and best regards,
Hans-Peter Suter


--
*
function riIsNull( _s: pSExp ): aRBoolean; cdecl;

vs.

function IsNaScalar( _x: pSExp ): boolean;
  begin
    result:= (riLength( _x ) = 1) and
             (riTypeOf( _x ) in [setLglSxp, setRealSxp]) and
             (rIsNa( riReal( riCoerceVector( _x, setRealSxp ) )[0] ) <> 0);
  end;



More information about the R-help mailing list