Bug 16411 - format() does not respect decimal.mark="." when options(OutDec=",")
Summary: format() does not respect decimal.mark="." when options(OutDec=",")
Status: CLOSED FIXED
Alias: None
Product: R
Classification: Unclassified
Component: Misc (show other bugs)
Version: R-devel (trunk)
Hardware: All All
: P5 major
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2015-06-04 16:13 UTC by Milan Bouchet-Valat
Modified: 2015-12-14 13:46 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Milan Bouchet-Valat 2015-06-04 16:13:18 UTC
format() and prettyNum() do not respect the decimal.mark="." argument when options(OutDec=",") has been called. This is pretty disruptive, as it makes some packages fail with cryptic errors. I see this on both R 3.2.0 and R-devel.

R Under development (unstable) (2015-06-04 r68471) -- "Unsuffered Consequences"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-unknown-linux-gnu (64-bit)
[...]

> options(OutDec=",")
> prettyNum(1.5, decimal.mark=".")
[1] "1,5"
> format(1.5, decimal.mark=".")
[1] "1,5"
>
> .Internal(format(1.5, FALSE, 2, 2, 2, 3L, FALSE, 1))
[1] "1,50"
Comment 1 Martin Maechler 2015-06-18 14:33:01 UTC
The help page for  prettyNum()  says
 
           Note that ‘prettyNum(x)’ may behave unexpectedly if ‘x’
     is a ‘character’ vector not resulting from something like
     ‘format(<number>)’: in particular it assumes that a period is a
     decimal mark.

unfortunately.  This really implies that format() -- often eventually calling format.default() and prettyNum() -- will typically not work with the 'OutDec'  option set.

Further note that formatC()'s default for the decimal mark has also been adapted only for R 3.2.0.... trying to fix other inconsistencies e.g. in packages which did not adapt their workings to the 'OutDec' option.

I have never liked or used this option myself, even though I live in Switzerland, where one "pronounces" the decimal dot as a "comma" orally.
But then everyone from high-school on is taught that you should use the decimal "." in science (and almost everywhere "serious") and not the ","...

In spite of all that, I -- as original author of prettyNum() now have a look to see if the situation can be improved without breaking other functionality.
I'm not sure this makes sense.  Do you think it would make sense to format numbers as using "l" (lowercase "L") instead of "1" (one)  and  "1" (one) instead of "7" .. just because of some historical hand writing conventions ?

So the bug is "ASSIGNED" for now, but we may resolve it as extreme as "INVALID", because strictly speaking, the documentation does mention that some parts only work with a decimal mark ==  "."
Comment 2 Milan Bouchet-Valat 2015-06-18 16:08:58 UTC
Thanks for looking at this. In France at least it seems to me that the comma is the standard when writing in French (that's mostly useful for graphs and when outputting tables, actually).

(In reply to Martin Maechler from comment #1)
> Do you think it would make sense to format
> numbers as using "l" (lowercase "L") instead of "1" (one)  and  "1" (one)
> instead of "7" .. just because of some historical hand writing conventions ?
Well, '.' is used in texts just as much as ',', so I don't see how the comparison holds. I think it's just a matter of national conventions -- problems only arise because people don't use the same character.
Comment 3 Martin Maechler 2015-06-20 20:17:29 UTC
I've ended up spending quite a bit of time on this ... also getting advice from other R core members (on the issue of 'OutDec' and that it's only partial requirement of being "one character").

I've now committed changes that fix this bug (r68563, 2015-06-20 18:12:26 +0200).

They entail different behavior, for other situations, too, notably the default for `print.mark` is now  `getOption("OutDec")`  also for
prettyNum() and format.default().... and I am "sure" this will break the some other packages checks (if not more).

Consequently, the changes are only to R-devel for the time being,
but are planned to be back ported to  "R 3.2.1 patched" (to become 3.2.2 sometime) as well.
Comment 4 Milan Bouchet-Valat 2015-06-21 12:13:44 UTC
Thanks!

I guess when you said 'print.mark' you meant 'decimal.mark'. FWIW, I'd even think this kind of change in defaults can wait for R 3.3. No need to break packages in a bugfix release.
Comment 5 751809522 2015-10-13 01:29:37 UTC
After updating to R-3.2.2, head(), summary() and view() cause an error.

Error in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3L,  : 
8 arguments passed to .Internal(format) which requires 9.

I'm a begginner and have no idea about how to solve the problem. I don't believe it's a big bug but it did disturb me.
Comment 6 Milan Bouchet-Valat 2015-10-13 07:14:19 UTC
Can you provide an example of code reproducing the problem, and post the output of sessionInfo()?
Comment 7 Martin Maechler 2015-10-13 10:21:09 UTC
(In reply to Milan Bouchet-Valat from comment #6)
> Can you provide an example of code reproducing the problem, and post the
> output of sessionInfo()?

It must be an old .RData of yours, or a package that you must re-oinstall under R 3.2.

Please go to the "R-help" (the mailing list) or another forum.
This all has nothing to do with fixing the bug which was reported and fixed.
Comment 8 Jens Henrik Badsberg 2015-11-23 10:09:42 UTC
Re. https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=16411

``big.mark = "."´´ is 'ignored' when ``decimal.mark = ","´´ is used for 'prettyNum' in 3.2.2, but OK in 3.2.0:


R version 3.2.2 (2015-08-14) -- "Fire Safety"

...

> prettyNum(1000.5, big.mark = ".", decimal.mark = ",")
[1] "1,000,5"
> prettyNum(1000.5, big.mark = "'", decimal.mark = ",")
[1] "1'000,5"
> prettyNum(1000.5, big.mark = ",", decimal.mark = ",")
[1] "1,000,5"
Advarselsbeskeder:
1: I prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3L,  :
  'big.mark' og 'decimal.mark' er begge ',', hvilket kan være forvirrende
2: I prettyNum(1000.5, big.mark = ",", decimal.mark = ",") :
  'big.mark' og 'decimal.mark' er begge ',', hvilket kan være forvirrende
> 

> getOption("OutDec")
[1] "."


R version 3.2.0 (2015-04-16) -- "Full of Ingredients"
...

>  prettyNum(1000.5, big.mark = ".", decimal.mark = ",")
[1] "1.000,5"
>  prettyNum(1000.5, big.mark = ",", decimal.mark = ",")
[1] "1,000,5"
Warning message:
In prettyNum(1000.5, big.mark = ",", decimal.mark = ",") :
  'big.mark' and 'decimal.mark' are both ',', which could be confusing
> 


Regards,

Jens Henrik Badsberg

PS: Denmark is similar to France here: "Milan Bouchet-Valat 2015-06-18 16:08:58 UTC: Thanks for looking at this. In France at least it seems to me that the comma is the standard when writing in French (that's mostly useful for graphs and when outputting tables, actually)."

PPS: And I am very sorry, if this quick e-mail is send to the wrong list.
Comment 9 Martin Maechler 2015-11-23 13:01:42 UTC
You are right.... this is quite bad....

... and worse is an example which you did not try :


> prettyNum(1000.2345, big.mark=".", decimal.mark=".")
[1] "1.000"

which is really really bad ... of course, it is not a good idea to have
'decimal.mark' ==  'big.mark'
and therefore the user gets too warnings from the above...
But this is still not acceptable.
Comment 10 Duncan Murdoch 2015-11-23 15:05:22 UTC
I agree with Jens that his example shows a problem, but I don't see a problem with Martin's example.  If a user asks for big.mark = ".", then one thousand should be displayed as "1.000".  The fact that the output is confusing is a user problem, not an R problem.
Comment 11 Martin Maechler 2015-11-23 19:32:56 UTC
(In reply to Duncan Murdoch from comment #10)
> I agree with Jens that his example shows a problem, but I don't see a
> problem with Martin's example.  If a user asks for big.mark = ".", then one
> thousand should be displayed as "1.000".  The fact that the output is
> confusing is a user problem, not an R problem.

Duncan: You have overlooked that all digits after the decimal point were lost!
Comment 12 Martin Maechler 2015-11-23 19:36:31 UTC
(In reply to Martin Maechler from comment #9)
> You are right.... this is quite bad....
> 
> ... and worse is an example which you did not try :
> 
> 
> > prettyNum(1000.2345, big.mark=".", decimal.mark=".")
> [1] "1.000"
> 
> which is really really bad ... of course, it is not a good idea to have
> 'decimal.mark' ==  'big.mark'
> and therefore the user gets too warnings from the above...
> But this is still not acceptable.

These (Jens bug and mine) are now fixed, in both R-devel and R-patched.
The bugs indeed where only in R 3.2.2, no other released version of R.