Displaying 20 results from an estimated 400 matches similar to: "Formatting zeroes with prettyNum"
2025 May 23
1
Formatting zeroes with prettyNum
You fed it two characters, "dash" and "space" and it only wanted one character so it truncated to the first character and warned you that that's what it did.
If you had your space before the dash, it would have used that as your replacement character
> prettyNum(0, zero.print = " - ", replace = TRUE)
[1] " "
Warning message:
In .format.zeros(x,
2025 May 23
1
Formatting zeroes with prettyNum
Tim,
The purpose of the `replace.zero` argument is to allow longer replacements.
See for example the behaviour with a character vector input:
> prettyNum("0", zero.print = "- ", replace.zero = TRUE)
[1] "- "
I'm pretty sure this is a bug, and have now posted the relevant details on r-devel.
A fix would be below.
Best,
Mikko
diff --git
2019 Mar 22
2
prettyNum digits=0 not compatible with scientific notation
FWIW, it doesn't seem to be happening on Mac OS:
> format(2^30, digits=0)
[1] "1.e+09"
> prettyNum(12345.6, digits=0)
[1] "1.e+04"
A glibc misfeature?
-pd
> On 22 Mar 2019, at 10:10 , Martin Maechler <maechler at stat.math.ethz.ch> wrote:
>
> Thank you, Robert for raising this here !
>
>>>>>> Robert McGehee
2025 May 23
1
Bug in prettyNum
? Fri, 23 May 2025 11:47:33 +0000
Marttila Mikko via R-devel <r-devel at 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) :
>
2025 May 26
1
Bug in prettyNum
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
>
2025 May 23
1
Bug in prettyNum
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
2025 May 27
1
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 at stat.math.ethz.ch>
wrote:
> Thank you, Marttila and Ivan,
>
> As
2019 Mar 21
3
prettyNum digits=0 not compatible with scientific notation
R developers,
Seems I get a bad result ("%#4.0-1e" in particular) when trying to use prettyNum digits=0 with scientific notation. I tried on both my Linux box and on an online R evaluator and saw the same problem, so it's not limited to my box at least. I see the problem in both R 3.5.3 and R 3.3.2.
options(scipen=-100)
prettyNum(1, digits=0)
[1] "%#4.0-1e"
prettyNum(2,
2002 May 13
1
prettyNum inserts leading commas (PR#1548)
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] <-
2019 Mar 22
0
prettyNum digits=0 not compatible with scientific notation
Thank you, Robert for raising this here !
>>>>> Robert McGehee
>>>>> on Thu, 21 Mar 2019 20:56:19 +0000 writes:
> R developers,
> Seems I get a bad result ("%#4.0-1e" in particular) when trying to use prettyNum digits=0 with scientific notation. I tried on both my Linux box and on an online R evaluator and saw the same problem, so
2019 Mar 22
0
prettyNum digits=0 not compatible with scientific notation
>>>>> peter dalgaard
>>>>> on Fri, 22 Mar 2019 17:30:19 +0100 writes:
> FWIW, it doesn't seem to be happening on Mac OS:
>> format(2^30, digits=0)
> [1] "1.e+09"
>> prettyNum(12345.6, digits=0)
> [1] "1.e+04"
> A glibc misfeature?
It seems (and note we are talking about format.default()
2018 May 25
4
options other than regex
Hi --
I'm looking for alternatives to regex for a fairly simply 'reformatting'
problem. Alternatives only because a lot of folks have trouble
parsing/interpreting regex expressions, and I'm looking for suggestions
for something more 'transparent'.
Here is an example of what I'm trying to do. Take the following string,
which I call x, and for each character in the
2008 Aug 07
1
Bug in format.default(): na.encode does not have any effect for (PR#12318)
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"
>
2018 May 25
0
options other than regex
Hi
I am not sure if it is more readable
> paste(paste(unlist(strsplit(x,"")),".", sep=""), collapse="")
[1] "1.0.1.1.0.1.1.1."
If you did not want last dot, it is a bit shorter.
> paste(unlist(strsplit(x,"")),collapse=".")
[1] "1.0.1.1.0.1.1.1"
>
Cheers
Petr
Tento e-mail a jak?koliv k n?mu p?ipojen?
2009 Nov 13
2
format (PR#14062)
Full_Name: Dirk Jacob
Version: R 2.8.1 and 2.9.1
OS: Win XP
Submission from: (NULL) (153.96.32.62)
I want to convert numbers to strings
like:
> inputs= c(0.3+0*(1:12) )
> (format(inputs,digits=3,scientific=T,collapse=" "))
and it works
[1] "3e-01" "3e-01" "3e-01" "3e-01" "3e-01" "3e-01" "3e-01"
2010 Aug 27
3
interpreting date-related error message
Hello, helpeRs,
I have a vector of numbers from 1-365 (days of the year) that I would
like to convert to a date. There are no NA's and no missing values.
I did not insert leading zero's for numbers less than 100.
Using the syntax:
dat$doy.1 <- as.numeric(format(dat$doy, "%j" ))
I get the following error message:
Error in prettyNum(.Internal(format(x, trim, digits,
2010 Feb 15
2
Printing 2 digits after decimal point
Hi there,
i'm not getting along with the following problem.
I'd like to print a real number, e.g.
x <- 12.3
with exactly two digits after the decimal point, e.g.
12.30
I've tried the whole format(), formatC() and prettyNum() functions but
did not have any success with it.
This should work with all real numbers, in case even with 0.0 (-> 0.00).
For cracks this thing is pretty
2008 Oct 17
2
Beginner's question: number formatting
Hello R-helpers,
I have a problem with formatting a single number to show leading zeros.
For example, I want "2" displayed as "002".
My numbers have 1 to 3 digits and I would like them all to display 3
digits for printing. I know I could use "paste" in a loop with several
"if"s, but I was wondering if there is a single function that can do this.
I have
2010 Feb 14
4
Newbie woes with *apply
Dataframe cust has Date-type column open.date. I wish to set up another
column, with (first day of) the quarter of open.date.
To be comprehensive (of course, improvement suggestions are welcome),
month = function(date)
{
return(as.numeric(format(date,"%m")))
}
first.day.of.month = function(date)
{
return(date + 1 - as.numeric(format(date,"%d")))
}
first.day.of.quarter =
2019 Mar 22
1
prettyNum digits=0 not compatible with scientific notation
> On 22 Mar 2019, at 18:07 , Martin Maechler <maechler at stat.math.ethz.ch> wrote:
>
> gives (on Linux R 3.5.3, Fedora 28)
>
> d=10 d=7 d=2 d=1 d=0
> [1,] "123456" "123456" "123456" "1e+05" "%#4.0-1e"
> [2,] "12345.6" "12345.6" "12346"