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

From: <Gregor.Gorjanc_at_bfro.uni-lj.si>
Date: Thu, 07 Aug 2008 12:14:18 +0200 (CEST)


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.

## 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
Received on Thu 07 Aug 2008 - 10:27:34 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 - 16:36:10 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