Skip to content
Prev 33035 / 63421 Next

Argument as.integer(NA) to a function C

On Thu, 18 Jun 2009, Christophe Genolini wrote:

            
Simple: Rprintf does not know about NAs (and nor does printf).  From 
the manual:

   The most useful function for printing from a C routine compiled into
   R is Rprintf.  This is used in exactly the same way as printf, but
   is guaranteed to write to R's output (which might be a GUI console
   rather than a file).

The value of NA is stored as NA_INTEGER = -2^32, and if you want your 
C code to be aware of it, *you* need to program so that value is 
treated specially.  (Since double NAs are stored as a particular NaN, 
the default C handling of doubles will probably do something sensible 
but careful code will also need to take the difference between NaNs 
into account.)