[R] binary coding of NA, Nan etc.

Prof Brian D Ripley ripley at stats.ox.ac.uk
Fri Sep 28 11:36:55 CEST 2001


On Fri, 28 Sep 2001, Johann Petrak wrote:

> I wonder which binary codings to use for the different
> "special" values used in R.
> I want to create binary coded files of double, int, and
> string values that should get read into R using readBin.

It depends on the system.  R uses different values for IEC 60559
(aka IEEE 754) systems and others.

> Now, what is the correct way to code NA, NaN, Inf, and -Inf
> for these types? The documentation for read/writeBin
> doesnt contain any info on that ...

(Well, it is not really a read/writeBin issue: we don't explain any of the
machine-specific details there.)

> (for int and string, there probably is only NA).
> How to do this portably?
>
> The program should be compiled seperately from R, so
> I cannot use R macros/configure for that.

That's partly what Rmathlib and Rmath.h are for.

On a IEEE-754 system use the IEEE-754 values for doubles.

For integers and logicals, the NA value is INT_MIN, 0xff000000 usually.

There is no special NA value for char * strings.  But generally the value
"NA" is interpreted as special.

Reading the R source is the best way to answer such Qs.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list