Re: [Rd] (PR#12318) Bug in format.default(): na.encode does not have any effect for

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Sat, 09 Aug 2008 15:34:45 +0100 (BST)

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

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Sat 09 Aug 2008 - 14:48:40 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 09 Aug 2008 - 17:36:12 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive