Skip to content

Commit cf57e3d

Browse files
committed
fix digits issue (commented out in get_precision()) revisit later
1 parent 6aba2c5 commit cf57e3d

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

R/probs_to_string.R

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,29 @@
1212

1313
#' @importFrom stats setNames
1414
#' @export
15-
get_precision <- function(x, ...){
16-
# from [Broman::get_precision()]
17-
# a bit of contortion here to control the scipen and digits options and have them returned to their initial values
18-
dots <- list("...")
19-
if(is.null(dots$set_digits) || dots$set_digits) {
20-
scipen <- options("scipen")$scipen
21-
digits <- options("digits")$digits
22-
on.exit(options(scipen=scipen, digits=digits))
23-
options(scipen=100, digits=21)
24-
}
15+
get_precision <- function(x, ...) {
16+
# from [Broman::get_precision()]
17+
# a bit of contortion here to control the scipen and digits options and have them returned to their initial values
18+
dots <- list("...")
19+
# if (is.null(dots$set_digits) || dots$set_digits) {
20+
# scipen <- options("scipen")$scipen
21+
# digits <- options("digits")$digits
22+
# on.exit(options(scipen=scipen, digits=digits))
23+
# options(scipen=1, digits=8)
24+
# }
2525

26-
if(length(x) > 1) { # deal with vector input
27-
return(setNames(vapply(x, get_precision, 1, set_digits=FALSE), NULL))
28-
}
26+
if (length(x) > 1) { # deal with vector input
27+
return(setNames(vapply(x, get_precision, 1, set_digits=FALSE), NULL))
28+
}
2929

30-
### here down, x is a single value
31-
if(is.na(x)) return(NA) # NA -> NA
32-
x <- as.character(x)
33-
if(!grepl(".", x, fixed=TRUE)) return(0)
34-
frac <- strsplit(x, ".", fixed=TRUE)[[1]][2]
35-
if(is.na(frac) || nchar(frac)==0) return(0)
36-
digits <- strsplit(frac, "", fixed=TRUE)[[1]]
37-
max(which(digits != "0"))
30+
### here down, x is a single value
31+
if(is.na(x)) return(NA) # NA -> NA
32+
x <- as.character(x)
33+
if(!grepl(".", x, fixed=TRUE)) return(0)
34+
frac <- strsplit(x, ".", fixed=TRUE)[[1]][2]
35+
if(is.na(frac) || nchar(frac)==0) return(0)
36+
digits <- strsplit(frac, "", fixed=TRUE)[[1]]
37+
max(which(digits != "0"))
3838
}
3939

4040
probs_to_string <- function(x, prefix = "q") {

vignettes/simple-forecasts.Rmd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ First, we download the data and process as before (hidden).
3535

3636

3737
```{r grab-epi-data, echo=FALSE}
38-
options(scipen = 0, digits = 7)
3938
theme_set(theme_bw())
4039
# y <- covidcast_signals(
4140
# c("doctor-visits", "jhu-csse"),

0 commit comments

Comments
 (0)