From Gregor.Gorjanc at bfro.uni-lj.si  Thu Aug  7 12:14:18 2008
From: Gregor.Gorjanc at bfro.uni-lj.si (Gregor.Gorjanc at bfro.uni-lj.si)
Date: Thu,  7 Aug 2008 12:14:18 +0200 (CEST)
Subject: [Rd] Bug in format.default(): na.encode does not have any effect
	for (PR#12318)
Message-ID: <20080807101419.01C8F282EFC1@mail.pubhealth.ku.dk>

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



[Rd] Bug in format.default(): na.encode does not have any effect for (PR#12318)
Gregor.Gorjanc at bfro.uni-lj.si