As mentioned in my comment, the easiest way I can think of would be to add a thousands
option to the argument list of print.default
and an if()
statement in the body.
print.default <- function (x, digits = NULL, quote = TRUE, na.print = NULL, print.gap = NULL,
right = FALSE, max = NULL, useSource = TRUE, thousands = TRUE, ...)
{
noOpt <- missing(digits) && missing(quote) && missing(na.print) &&
missing(print.gap) && missing(right) && missing(max) &&
missing(useSource) && missing(...)
if(thousands) {
return(formatC(x, format="d", big.mark=","))
}
.Internal(print.default(x, digits, quote, na.print, print.gap,
right, max, useSource, noOpt))
}
Now we will have to wrap with print
, but it works well.
print(1:10 * 100000)
# [1] "100,000" "200,000" "300,000" "400,000" "500,000" "600,000"
# [7] "700,000" "800,000" "900,000" "1,000,000"
print(1:10 * 100000, thousands=FALSE)
# [1] 1e+05 2e+05 3e+05 4e+05 5e+05 6e+05 7e+05 8e+05 9e+05 1e+06