MichaelChirico / r-bugs

A ⚠️read-only⚠️mirror of https://bugs.r-project.org/
20 stars 0 forks source link

[BUGZILLA #16322] scipen generates errors for large values #5738

Open MichaelChirico opened 4 years ago

MichaelChirico commented 4 years ago

There's something wrong with the scipen option. I've tried the commands below on R-3.1.1, R-3.1.2, and R-3.1.3 in Windows, and also Linux version 3.0.1 (both Rstudio and "regular"). I get the same exact results in all these platforms/versions. The problems occur near scipen value 2^31=2147483648. The library() errors below have occured with every package I tried, more than just the two examples, MASS and nnet, below. Actually, if one does NOT successfully load a package before changing scipen to 2^31 and reloading, there are more warning details (see last example way at the bottom). (Yes, I realize no one would need a scipen value this large. So the bug fix will probably be to min the argument with a certain maximum scipen. Unless this reveals some underlying bug with wider impact. Note that many users wanting to avoid all scientific notation might approach the scipen option by randomly drumming up a very large number on the keyboard, so this bug might actually occur rather frequently in practice.)

options(scipen=2147483642)
1

[1] 1

options(scipen=2147483643)
1

[1] 1e+00

options(scipen=2147483644)
1

[1] 1e+00

options(scipen=2147483645)
1

[1] 1e+00

options(scipen=2147483646)
1

[1] 1e+00

options(scipen=2147483647)
1

[1] 1e+00

options(scipen=2147483648)
1

[1] 1 Warning message: NAs introduced by coercion

options(scipen=2147483647)
library(nnet)
options(scipen=2147483648)
library(nnet)

Warning message: In paste("package", package, sep = ":") : NAs introduced by coercion

options(scipen=2147483647)
library(MASS)
options(scipen=2147483648)
library(MASS)

Warning message: In paste("package", package, sep = ":") : NAs introduced by coercion

Here are the commands so they can be pasted in for debugging:

options(scipen=2147483642) 1 options(scipen=2147483643) 1 options(scipen=2147483644) 1 options(scipen=2147483645) 1 options(scipen=2147483646) 1 options(scipen=2147483647) 1 options(scipen=2147483648) 1 options(scipen=2147483647) library(nnet) options(scipen=2147483648) library(nnet) options(scipen=2147483647) library(MASS) options(scipen=2147483648) library(MASS)

Example if one does NOT successfully load a package before changing scipen to 2^31 and reloading: R started anew, then:

options(scipen=2^31)
library(MASS)

There were 50 or more warnings (use warnings() to see the first 50)

warnings()

Warning messages: 1: In paste("package", package, sep = ":") : NAs introduced by coercion 2: In paste0("^", pkg, "$") : NAs introduced by coercion 3: In paste0("^", pkg, "$") : NAs introduced by coercion 4: In paste(x[c("major", "minor")], collapse = ".") : NAs introduced by coercion 5: In paste("package", pkg, sep = ":") : NAs introduced by coercion 6: In paste("package", pkg, sep = ":") : NAs introduced by coercion 7: In paste("package", pkg, sep = ":") : NAs introduced by coercion 8: In paste("package", pkg, sep = ":") : NAs introduced by coercion 9: In paste0("^", pkg, "$") : NAs introduced by coercion 10: In paste0("^", pkg, "$") : NAs introduced by coercion 11: In paste("imports", name, sep = ":") : NAs introduced by coercion 12: In paste("lazydata", name, sep = ":") : NAs introduced by coercion 13: In gettext("replacing previous import by %s when loading %s") : NAs introduced by coercion 14: In gettext("replacing previous import by %s when loading %s") : NAs introduced by coercion 15: In gettext("replacing previous import by %s when loading %s") : NAs introduced by coercion 16: In gettext("replacing previous import by %s when loading %s") : NAs introduced by coercion 17: In gettext("replacing previous import by %s when loading %s") : NAs introduced by coercion 18: In gettext("replacing previous import by %s when loading %s") : NAs introduced by coercion 19: In gettext("replacing previous import by %s when loading %s") : NAs introduced by coercion 20: In gettext("replacing previous import by %s when loading %s") : NAs introduced by coercion 21: In gettext("replacing previous import by %s when loading %s") : NAs introduced by coercion 22: In gettext("replacing previous import by %s when loading %s") : NAs introduced by coercion 23: In gettext("replacing previous import by %s when loading %s") : NAs introduced by coercion 24: In gettext("replacing previous import by %s when loading %s") : NAs introduced by coercion 25: In gettext("replacing previous import by %s when loading %s") : NAs introduced by coercion 26: In gettext("replacing previous import by %s when loading %s") : NAs introduced by coercion 27: In gettext("replacing previous import by %s when loading %s") : NAs introduced by coercion 28: In gettext("replacing previous import by %s when loading %s") : NAs introduced by coercion 29: In glue(filebase, "rdx", sep = ".") : NAs introduced by coercion 30: In glue(filebase, "rdb", sep = ".") : NAs introduced by coercion 31: In paste0(dbbase, ".rdb") : NAs introduced by coercion 32: In paste0(dbbase, ".rdb") : NAs introduced by coercion 33: In glue(filebase, "rdx", sep = ".") : NAs introduced by coercion 34: In glue(filebase, "rdb", sep = ".") : NAs introduced by coercion 35: In paste(info[, 1], info[, 2], sep = ".") : NAs introduced by coercion 36: In paste0(chname, file.ext) : NAs introduced by coercion 37: In paste0("^", pkg, "$") : NAs introduced by coercion 38: In paste(gsub("/", "\\", DLLpath), PATH, sep = ";") : NAs introduced by coercion 39: In paste0(fixes[1L], sym$name, fixes[2L]) : NAs introduced by coercion 40: In paste0(fixes[1L], sym$name, fixes[2L]) : NAs introduced by coercion 41: In paste0(fixes[1L], sym$name, fixes[2L]) : NAs introduced by coercion 42: In paste0(fixes[1L], sym$name, fixes[2L]) : NAs introduced by coercion 43: In paste0(fixes[1L], sym$name, fixes[2L]) : NAs introduced by coercion 44: In paste0(fixes[1L], sym$name, fixes[2L]) : NAs introduced by coercion 45: In paste0(fixes[1L], sym$name, fixes[2L]) : NAs introduced by coercion 46: In paste0(fixes[1L], sym$name, fixes[2L]) : NAs introduced by coercion 47: In paste0(fixes[1L], sym$name, fixes[2L]) : NAs introduced by coercion 48: In paste0(fixes[1L], sym$name, fixes[2L]) : NAs introduced by coercion 49: In paste0(fixes[1L], sym$name, fixes[2L]) : NAs introduced by coercion 50: In paste0(fixes[1L], sym$name, fixes[2L]) : NAs introduced by coercion There were 50 or more warnings (use warnings() to see the first 50)


METADATA

MichaelChirico commented 4 years ago

On 2^31: that's the maximum storage size of a C INT, which is the type used to store numbers in R (the transition to LONGs is happening, but is still gradual). This is the same reason that, for a very long time, you could only have 2^31-1-length objects - the index would integer overflow.

Example:

example_object <- character(2147483648)

Error in structure(.Call(C_objectSize, x), class = "object_size") : long vectors not supported yet: unique.c:1655

So, I suspect that that's why NAs are introduced by coercion - because it's trying to expand a number to a digit it cannot hold. The package errors are weirder, but...some kind of numeric manipulation in the load or run process, I guess?


METADATA

github-actions[bot] commented 4 years ago

NA


METADATA