 # Might this be a bug in R print()? If so, where to open an issue?

I tried to trick the print statement for 100.000 where I wanted all 6 digits printed not `1e+05 `.
So my idea was to just add 0.1 to 100.000 and then force no digits after the decimal point by setting `digits=0`.

In general `digits=0` works:

``````> print(1000+0.1, digits=0)
``````

` 1000`

but in my case:

``````> print(100000 + 0.1, digits = 0)
``````

`%#5.0-1e`

Help says about `digits` in `print.default`:

a non-null value for digits specifies the minimum number of significant digits to be printed in values. The default, NULL, uses getOption("digits"). (For the interpretation for complex numbers see signif.) Non-integer values will be rounded down, and only values greater than or equal to 1 and no greater than 22 are accepted.

Checked the issue in base R (4.0.3, SUSELinux), so not an RStudio issue. But I could not figure where else I could ask about it.

Am I wrong? Is R wrong?

Edit: see below, talking about 100,000 not 100.000

Think of significant digits argument in terms of how many are needed to display the full value.

``````print(100000.1)
#>  100000.1
print(100000.1, digits = 0)
#> %#5.0-1e
print(100000.1, digits = 1)
#>  1e+05
print(100000.1, digits = 7)
#>  100000.1
``````

Sorry my fault, the text was in English but with German numbers, the problem not comprehensible.

Should be:

I tried to trick the print statement for 100,000 where I wanted all 6 digits printed not `1e+05 `.
So my idea was to just add 0.1 to 100,000 and then force no digits after the decimal point by setting `digits=0`.

And this result you get with `digits=0` is no good, I still think.

Here are two ways

``````options("scipen"= 100, "digits"=4)
plain <- function(x) sprintf("%.0f", x)
powers <- c(1,1e1,1e2,1e3,1e4,1e5,1e6,1e7,1e8,1e9)
print(powers)
#>            1         10        100       1000      10000     100000
#>      1000000   10000000  100000000 1000000000
plain(powers)
#>   "1"          "10"         "100"        "1000"       "10000"
#>   "100000"     "1000000"    "10000000"   "100000000"  "1000000000"
``````

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.