wrong measurements on as.character(NA) (PR#1739)
ripley@stats.ox.ac.uk
ripley@stats.ox.ac.uk
Fri, 5 Jul 2002 07:31:37 +0100 (BST)
Jens,
I put a fix in, but it caused other problems and I am now not sure about
this and will revert it. Thanks for raising the issue, but the answers do
not seem incorrect to me.
If nchar(x) gives the number of characters in the string, then of course
the result should be NA. However, it seems to be widely used as the
number of characters in the printed representation of a string, when 2
is correct. (E.g. in format.character.)
I am less clear about strwidth and strheight. In general an NA string
will not be plotted, so 0 seems the appropriate answer, but if it were
plotted the current answer is correct.
Calling strwidth or strheight on a logical vector (and NA is logical)
is correctly an error.
Brian
On Wed, 3 Jul 2002 oehl_list@gmx.de wrote:
>
> pure replication code at the end
>
> > ## this is correct
> > nchar("NA")
> [1] 2
> >
> > # but this is wrong since 1.5.0
> > nchar(NA)
> [1] 2
> > nchar(as.character(NA))
> [1] 2
> >
> >
> > # same problems with strwidth() strheight()
> > plot(1)
> > strwidth("NA")
> [1] 0.03410118
> > strwidth(NA)
> Error in strwidth(s, pmatch(units, c("user", "figure", "inches")), cex) :
> character or expression first argument expected
> > strwidth(as.character(NA))
> [1] 0.03410118
> >
> > strheight("NA")
> [1] 0.02235669
> > strheight(NA)
> Error in strheight(s, pmatch(units, c("user", "figure", "inches")), cex) :
> character or expression first argument expected
> > strheight(as.character(NA))
> [1] 0.02235669
>
>
> I guess, all of the following should return NA
>
> nchar(NA)
> strwidth(NA)
> strheight(NA)
>
> Best
>
>
> Jens Oehlschlägel
>
>
>
> ## this is correct
> nchar("NA")
>
> # but this is wrong since 1.5.0
> nchar(NA)
> nchar(as.character(NA))
>
>
> # same problems with strwidth() strheight()
> plot(1)
> strwidth("NA")
> strwidth(NA)
> strwidth(as.character(NA))
>
> strheight("NA")
> strheight(NA)
> strheight(as.character(NA))
>
>
> --please do not edit the information below--
>
> Version:
> platform = i386-pc-mingw32
> arch = i386
> os = Win32
> system = i386, mingw32
> status =
> major = 1
> minor = 5.1
> year = 2002
> month = 06
> day = 17
> language = R
>
> Windows 2000 Professional (build 2195) Service Pack 1.0
>
> Search Path:
> .GlobalEnv, package:SJava, package:ctest, Autoloads, package:base
>
> --
>
>
>
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
--
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._