From ripley@stats.ox.ac.uk  Fri May 17 15:48:43 2002
From: ripley@stats.ox.ac.uk (ripley@stats.ox.ac.uk)
Date: Fri, 17 May 2002 16:48:43 +0200 (MET DST)
Subject: [Rd] type.convert() does not treat "NA" as ordinary string as (PR#1568)
Message-ID: <200205171448.QAA21029@pubhealth.ku.dk>

On Fri, 17 May 2002 oehl_list@gmx.de wrote:

> # replication code at end of mail
>
> > # As from R 1.5
> >
> > identical(as.character(NA), "NA")
> [1] FALSE
> >
> > # there is no longer a fundamental difference between "NA"
> > # and an ordinary string like "NN" (WHICH IS A GREAT IDEA!!)
> > # however, though "NA" is not given as na.strings we have
> >
> > type.convert(c("NA", "1", NA), na.strings="b")
> [1] NA  1 NA
> > # compare to
> > type.convert(c("NN", "1", NA), na.strings="b")
> [1] NN   1    <NA>
> Levels:  1 NN NA
> >
> > # dito
> > type.convert(c("NA", "1", NA), na.strings=character())
> [1] NA  1 NA
> > # compare to
> > type.convert(c("NN", "1", NA), na.strings=character())
> [1] NN   1    <NA>
> Levels:  1 NN NA

Yes. Thanks for pointing it out.
Notice that is a real result, as the real convertor was hard-coded to
handle "NA" as a missing real.  It proved a little tricky to disentangle
it.

> # furthermore, may be type.convert should have default
> # function(x, na.strings = NA, as.is = FALSE, dec = ".")
> # or
> # function(x, na.strings = character(), as.is = FALSE, dec = ".")
> # or
> # function(x, na.strings = NULL, as.is = FALSE, dec = ".")
> # rather then
> # function(x, na.strings = "NA", as.is = FALSE, dec = ".")

That was intentional.  It is intended to convert character input read from
a file, and R does still regards "NA" in a file as missing unless told
otherwise.  So it makes sense to have the same default for type.convert,
and also for backwards compatibility.

Brian

-- 
Brian D. Ripley,                  ripley@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-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] type.convert() does not treat "NA" as ordinary string as (PR#1568)
ripley@stats.ox.ac.uk