[Rd] Bug in prettyNum
Marttila Mikko
m|kko@m@rtt||@ @end|ng |rom or|onph@rm@@com
Mon Jun 2 13:26:30 CEST 2025
Hi,
Thanks, Ivan, for the additional diagnosis and debugging tips.
Thanks, Martin, for the prompt fix.
Thanks, Toby, for sharing the R Dev Container link. I tried it out and was able to easily test some changes. I'll be using that in the future!
Best,
Mikko
-----Original Message-----
From: R-devel <r-devel-bounces using r-project.org> On Behalf Of Toby Hocking
Sent: Tuesday, 27 May 2025 08:17
To: Marttila Mikko via R-devel <r-devel using r-project.org>
Subject: Re: [Rd] Bug in prettyNum
Thanks for the contribution Mikko!
For testing future patches, you can actually do it right in the web browser, thanks to Heather Turner's R Dev Container, see instructions here https://contributor.r-project.org/r-dev-env/container_setup/
Best
Toby
On Mon, May 26, 2025 at 6:28 PM Martin Maechler <maechler using stat.math.ethz.ch>
wrote:
> Thank you, Marttila and Ivan,
>
> As the original author of prettyNum() {etc ..}, I will commit such a
> bug fix to R-devel (and probably port it to R 4.5.0 patched) quite
> soon (but not yet today).
>
> Best regards,
>
> Martin Maechler
>
> >>>>> Ivan Krylov via R-devel
> >>>>> on Fri, 23 May 2025 17:14:57 +0300 writes:
>
> > В Fri, 23 May 2025 11:47:33 +0000
> > Marttila Mikko via R-devel <r-devel using r-project.org> пишет:
>
> >> 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'
>
> >> Please see below a patch which I believe would fix this.
>
> > Surprisingly, it's not enough. The 'replace' argument to
> .format.zeros
> > needs to be "threaded" through both the call to vapply(x,
> format,
> ...)
> > and the internal call from format.default(...) to prettyNum(...):
>
> R> options(warn = 2, error = recover)
> R> prettyNum(0, zero.print = "--", replace.zero = TRUE)
> > Error in .format.zeros(x, zero.print, replace = replace.zero) :
> > (converted from warning) 'zero.print' is truncated to fit into
> formatted zeros; consider 'replace=TRUE'
>
> > Enter a frame number, or 0 to exit
>
> > 1: prettyNum(0, zero.print = "--", replace.zero = TRUE)
> > 2: vapply(x, format, "", big.mark = big.mark, big.interval =
> big.interval, sma
> > 3: FUN(X[[i]], ...)
> > 4: format.default(X[[i]], ...)
> > 5: prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3,
> na.encode, sc
> > 6: .format.zeros(x, zero.print, replace = replace.zero)
> > 7: warning("'zero.print' is truncated to fit into formatted
> zeros; consider 'r
> > <...omitted...>
> > Selection: 6
> > <...>
> > Browse[1]> ls.str()
> > i0 : logi TRUE
> > ind0 : int 1
> > nc : int 1
> > nx : num 0
> > nz : int 2
> > replace : logi FALSE
> > warn.non.fitting : logi TRUE
> > x : chr "0"
> > zero.print : chr "--"
>
> > Since prettyNum() accepts ... and thus ignores unknown arguments, it
> > seems to be safe to forward the ellipsis from format.default() to
> > prettyNum(). The patch survives LANGUAGE=en TZ=UTC make check-devel.
>
> > Index: src/library/base/R/format.R
> > ===================================================================
> > --- src/library/base/R/format.R (revision 88229)
> > +++ src/library/base/R/format.R (working copy)
> > @@ -73,7 +73,7 @@
> > decimal.mark = decimal.mark, input.d.mark = decimal.mark,
> > zero.print = zero.print, drop0trailing = drop0trailing,
> > is.cmplx = is.complex(x),
> > - preserve.width = if (trim) "individual" else
> "common"),
> > + preserve.width = if (trim) "individual" else
> "common", ...),
> > ## all others (for now):
> > stop(gettextf("Found no format() method for class \"%s\"",
> > class(x)), domain = NA))
> > @@ -338,7 +338,8 @@
> > 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, ...)
> > + drop0trailing=drop0trailing, replace.zero=replace.zero,
> > + ...)
> > }
> > ## be fast in trivial case, when all options have their default,
> or "match"
> > nMark <- big.mark == "" && small.mark == "" && (notChar ||
> decimal.mark == input.d.mark)
>
>
> > --
> > Best regards,
> > Ivan
>
> > ______________________________________________
> > R-devel using r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
>
> ______________________________________________
> R-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
[[alternative HTML version deleted]]
______________________________________________
R-devel using r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
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.
More information about the R-devel
mailing list