From jens.oehlschlaegel-akiyoshi@mdfactory.de  Tue Jan  4 09:37:03 2000
From: jens.oehlschlaegel-akiyoshi@mdfactory.de (jens.oehlschlaegel-akiyoshi@mdfactory.de)
Date: Tue, 4 Jan 2000 10:37:03 +0100 (MET)
Subject: formatC (bug and fix) (PR#394)
Message-ID: <200001040937.KAA02096@pubhealth.ku.dk>


OK:

> formatC(as.double(c(1,0,NA)))
[1] "1"  "0"  "NA"


NOT OK:

> formatC(as.integer(c(1,0,NA)))
[1] "0"          "1072693248" "NA"

> formatC(as.integer(c(0,1,NA)))
[1] "0"  "0"  "NA"


BUG TRACED TO R-code of formatC()

where

        x[!Ok] <- 0

unintendedly changes the storage.mode of x to double, while variable mode
still signifies 'integer'. Thus the following is probably ok as bug fix

        ProperZero <- 0
        storage.mode(ProperZero) <- mode
        x[!Ok] <- ProperZero


At least the following tests are positive using this fix

> formatC(as.integer(c(1,0,NA)))
[1] "1"  "0"  "NA"
> formatC(as.double(c(1,0,NA)))
[1] "1"  "0"  "NA"
>
> formatC(as.integer(c(1,0,NA)), format="d")
[1] "1"  "0"  "NA"
> formatC(as.double(c(1,0,NA)), format="d")
[1] "1"  "0"  "NA"
> formatC(as.integer(c(1,0,NA)), format="f")
[1] "1.0000" "0.0000" "NA"
> formatC(as.double(c(1,0,NA)), format="f")
[1] "1.0000" "0.0000" "NA"
>
> formatC(as.integer(c(1,0,NA)), mode="integer")
[1] "1"  "0"  "NA"
> formatC(as.double(c(1,0,NA)), mode="integer")
[1] "1"  "0"  "NA"
> formatC(as.integer(c(1,0,NA)), mode="double")
[1] "1"  "0"  "NA"
> formatC(as.double(c(1,0,NA)), mode="double")
[1] "1"  "0"  "NA"
>
> formatC(as.integer(c(1,0,NA)), mode="integer", format="d")
[1] "1"  "0"  "NA"
> formatC(as.double(c(1,0,NA)), mode="integer", format="d")
[1] "1"  "0"  "NA"
> formatC(as.integer(c(1,0,NA)), mode="double", format="d")
[1] "1"  "0"  "NA"
> formatC(as.double(c(1,0,NA)), mode="double", format="d")
[1] "1"  "0"  "NA"
>
> formatC(as.integer(c(1,0,NA)), mode="integer", format="f")
[1] "1.0000" "0.0000" "NA"
> formatC(as.double(c(1,0,NA)), mode="integer", format="f")
[1] "1.0000" "0.0000" "NA"
> formatC(as.integer(c(1,0,NA)), mode="double", format="f")
[1] "1.0000" "0.0000" "NA"
> formatC(as.double(c(1,0,NA)), mode="double", format="f")
[1] "1.0000" "0.0000" "NA"


> version
         _
platform Windows
arch     x86
os       Win32
system   x86, Win32
status
major    0
minor    90.1
year     1999
month    December
day      15
language R


Best regards


--
Dr. Jens Oehlschlgel-Akiyoshi
MD FACTORY GmbH
Bayerstrasse 21

80335 Mnchen

Tel.: 089 545 28-27
Fax.: 089 545 28-10
http://www.mdfactory.de

Standard Disclaimers: Opinions expressed here are personal
and are not otherwise represented.



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


formatC (bug and fix) (PR#394)
jens.oehlschlaegel-akiyoshi@mdfactory.de