[Rd] (PR#12318) Bug in format.default(): na.encode does not have any effect for
Prof Brian Ripley
ripley at stats.ox.ac.uk
Sat Aug 9 16:34:45 CEST 2008
Have you read the help page? It says
na.encode: logical: should 'NA' strings be encoded?
No mention of encoding NA numerical values that I can see, and it was
never intended to apply to other than *strings*.
Please do the homework the FAQ asks of you and only use R-bugs if you
'know for certain' -- in particular, do heed
'Rather than jumping to conclusions, show the problem to someone who
knows for certain'
On Thu, 7 Aug 2008, Gregor.Gorjanc at bfro.uni-lj.si wrote:
> Hi!
>
> If I use format() on numeric vector, na.encode argument does not have any e=
> ffect. This
> was reported before:
> - https://stat.ethz.ch/pipermail/r-help/2007-October/143881.html
> - http://tolstoy.newcastle.edu.au/R/e2/devel/06/09/0360.html
>
> It works for other (say character) classes!
>
>> format(c("a", NA), na.encode=3DTRUE)
> [1] "a " "NA"
>
>> format(c("a", NA), na.encode=3DFALSE)
> [1] "a" NA
>
> I explored this a bit and found out that format.default() uses prettyNum(.I=
> nternal(format(...)))
> for formatting the logical, numeric, complex, ... classes. Simple tests (se=
> e bellow) show that
> .Internal(format()) does not obey the na.encode argument.
It works as documented (and coded).
>
> ## Encode NA as "NA"
>> .Internal(format(x=3Dc(1, NA), trim=3DFALSE, digits=3DNULL, nsmall=3D0, w=
> idth=3DNULL, adj=3D1, na.encode=3DTRUE, scientific=3DNA))
> [1] " 1" "NA"
>
> ## Do not encode NA as "NA"
>> .Internal(format(x=3Dc(1, NA), trim=3DFALSE, digits=3DNULL, nsmall=3D0, w=
> idth=3DNULL, adj=3D1, na.encode=3DFALSE, scientific=3DNA))
> [1] " 1" "NA"
> ## --> no effect
>
> ## Does prettyNum encode NA as "NA"
>> prettyNum(c("1", NA))
> [1] "1" NA
> ## --> not for character
>
>> prettyNum(c(1, NA))
> [1] "1" "NA"
> ## --> but it does for numeric
>
> I did all my tests with my Ubuntu box running R
>
>> version
> _
> platform i486-pc-linux-gnu
> arch i486
> os linux-gnu
> system i486, linux-gnu
> status
> major 2
> minor 7.1
> year 2008
> month 06
> day 23
> svn rev 45970
> language R
> version.string R version 2.7.1 (2008-06-23)
>
> --
> Lep pozdrav / With regards,
> Gregor Gorjanc
> ----------------------------------------------------------------------
> University of Ljubljana PhD student
> Biotechnical Faculty www: http://gregor.gorjanc.googlepages.com
> Zootechnical Department blog: http://ggorjan.blogspot.com
> Groblje 3 mail: gregor.gorjanc <at> bfro.uni-lj.si
> SI-1230 Domzale fax: +386 (0)1 72 17 888
> Slovenia, Europe tel: +386 (0)1 72 17 861
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
--
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 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-devel
mailing list