Closed kinto-b closed 3 years ago
I'd recommend setting default rounding as a package option
100%
Only question would be how to allow the user to override that behaviour on an ad hoc one-off basis
Hmmm, good call
I reckon a global option, prj_digits=2
, plus a digits
argument to prj_project
(and associated functions), is the best way to go.
Then we add a transformer to glue_each_in()
can_numeric <- function (x) {
!any(!is.na(x) & is.na(suppressWarnings(as.numeric(x))))
}
round_transformer <- function(digits = getOption("prj_digits")) {
function(text, envir) {
if (can_numeric(text)) text <- round(as.numeric(text), digits)
glue::identity_transformer(text, envir)
}
}
And we have in prj_cast_shadow()
if (!is.null(digits)) {
oldopts <- options(list(prj_digits = digits)
on.exit(options(oldopts))
}
Currently pretty much every shadow will include a call to
signif
, e.g.We should do rounding to 2 significant figures by default