Dear list,

I'd like to report a bug in `prettyNum()`. When called with a numeric vector, 
the `replace.zero` argument is disregarded.

> prettyNum(0, zero.print = "- ", replace.zero = TRUE)
[1] "-"
Warning message:
In .format.zeros(x, zero.print, replace = replace.zero) :
  'zero.print' is truncated to fit into formatted zeros; consider 'replace=TRUE'

A character vector as input works as expected:

> prettyNum("0", zero.print = "- ", replace.zero = TRUE)
[1] "- "

Please see below a patch which I believe would fix this. I haven't tested it as 
I can't easily compile R from source with my setup.

Best,

Mikko

diff --git a/src/library/base/R/format.R b/src/library/base/R/format.R
index 63fef83..1afadd3 100644
--- a/src/library/base/R/format.R
+++ b/src/library/base/R/format.R
@@ -338,7 +338,7 @@ prettyNum <-
                    big.mark=big.mark, big.interval=big.interval,
                    small.mark=small.mark, small.interval=small.interval,
                    decimal.mark=decimal.mark, zero.print=zero.print,
-                   drop0trailing=drop0trailing, ...)
+                   replace.zero=replace.zero, drop0trailing=drop0trailing, ...)
     }
     ## be fast in trivial case, when all options have their default, or "match"
     nMark <- big.mark == "" && small.mark == "" && (notChar || decimal.mark == 
input.d.mark)


This e-mail transmission may contain confidential or legally privileged 
information that is intended only for the individual or entity named in the 
e-mail address. If you are not the intended recipient, you are hereby notified 
that any disclosure, copying, distribution, or reliance upon the contents of 
this e-mail is strictly prohibited. If you have received this e-mail 
transmission in error, please reply to the sender, so that they can arrange for 
proper delivery, and then please delete the message from your computer systems. 
Thank you.

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to