[Rd] Re: [R] Several R vs S-Plus issues

Luke Tierney luke@nokomis.stat.umn.edu
Thu, 4 Oct 2001 14:25:28 -0500


On Thu, Oct 04, 2001 at 11:31:52AM -0700, Thomas Lumley wrote:
> On Thu, 4 Oct 2001, Duncan Murdoch wrote:
> 
> > On Thu, 4 Oct 2001 18:14:48 +0200, Kurt Hornik wrote in message
> > <15292.35576.513722.492732@mithrandir.hornik.net>:
> >
> > >Agreed.  As Peter said, subscripting by NA should give NA but R cannot
> > >distinguish a string NA from the string NA.
> >
> > But it does make some sort of distinction, as my example contrasting
> > "NA" with paste(NA) shows.  In case you missed it:
> >
> >  > is.na("NA")
> >  [1] TRUE
> >  > paste(NA)
> >  [1] "NA"
> >  > is.na(paste(NA))
> >  [1] FALSE
> >
> 
> Yes.  is.na() of a string is true if that string is actually a reference
> to R_NaString.  Parsing a literal "NA" will give R_NaString, as will
> coercing NA from some other type.  However, paste() doesn't check whether
> it produces "NA". Neither does toupper()
>   > is.na(toupper("na"))
>   [1] FALSE
>   > toupper("na")
>   [1] "NA"
> 
> 
> So we're partway there already, in fact.  It looks like we basically
> need to
> 1) stop the parser generating R_NaString from \"NA\"
> 2) Change PRINTNAME(R_NaString) to avoid ambiguity
> 

One more (at least :-))

3) fix saveload.c to preserve NA status in strings.

Right now we have

> x<-as.character(list(NA, "NA", paste(NA)))
> x
[1] "NA" "NA" "NA"
> is.na(x)
[1]  TRUE  TRUE FALSE
> save(list="x", file="tmp.RData")
> load("tmp.RData")
> x
[1] "NA" "NA" "NA"
> is.na(x)
[1] FALSE FALSE FALSE

It's easy enough to fix in principle--just add another case to
NewSaveSpecialHook and NewLoadSpecialHook.  Unfortunately this means
workspace files that contain string NA's written with this new
convention won't be readable by older versions of R (I think it will
generate an "unknown type" error) (and probably leave the file
opened).

luke

-- 
Luke Tierney
University of Minnesota                      Phone:           612-625-7843
School of Statistics                         Fax:             612-624-8868
313 Ford Hall, 224 Church St. S.E.           email:      luke@stat.umn.edu
Minneapolis, MN 55455 USA                    WWW:  http://www.stat.umn.edu
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._