[Rd] prettyNum inserts leading commas (PR#1548)
brahm@alum.mit.edu
brahm@alum.mit.edu
Mon, 13 May 2002 20:22:25 +0200 (MET DST)
Under R-1.5.0 on Solaris 2.6:
R> prettyNum(123456789, big.mark=",")
[1] ",123,456,789"
and that bad behavior (leading comma) spills into formatC as well:
R> formatC(123456789, digits=0, format="f", big.mark=",")
[1] ",123,456,789"
Looks to me like a bug in src/library/base/R/format.R, in function prettyNum:
B.[i.big] <- revStr(gsub(P0("([0-9]{",big.interval,"})"), # Original
P0("\\1",big.mark), revStr(B.[i.big])))
where we reverse the "before-the-decimal" string, then put a comma after each
set of 3 digits. One solution is to make the first regexp check that it is not
followed by a word boundary, i.e. add "\\B" to the end of it:
B.[i.big] <- revStr(gsub(P0("([0-9]{",big.interval,"})\\B"), # DB's fix
P0("\\1",big.mark), revStr(B.[i.big])))
which seems to correct the problem:
R-with-fix> prettyNum(123456789, big.mark=",")
[1] "123,456,789"
--
-- David Brahm (brahm@alum.mit.edu)
Version:
platform = sparc-sun-solaris2.6
arch = sparc
os = solaris2.6
system = sparc, solaris2.6
status =
major = 1
minor = 5.0
year = 2002
month = 04
day = 29
language = R
Search Path:
.GlobalEnv, package:misc, package:io, package:arrays, package:ls1, package:g.data, package:db, package:ts, package:ctest, Autoloads, package:base
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._