From 715877b259808ff0fca4f0a98f5a0909d0b77a3a Mon Sep 17 00:00:00 2001 From: Xiaosong Zhang Date: Tue, 26 Jul 2022 18:24:01 -0400 Subject: [PATCH] Allow rounding of numbers in output when quantities include "percentage" --- R/setup_geometry.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/R/setup_geometry.R b/R/setup_geometry.R index 4be6c01d..8008d36a 100644 --- a/R/setup_geometry.R +++ b/R/setup_geometry.R @@ -144,6 +144,10 @@ setup_geometry <- function(x, if (do_quantities) { digits <- options("digits")$digits + # get round parameter from options("round"), if not set, use default value 0 + round <- ifelse(is.null(options("round")$round) != TRUE, + options("round")$round, + 0) num <- orig[centers$id[singles | others]] if (is.null(quantities$labels)) { @@ -151,7 +155,7 @@ setup_geometry <- function(x, if ("percent" %in% type) { perc <- num/sum(num, na.rm = TRUE)*100 - perc <- ifelse(perc >= 1, as.character(round(perc)), "< 1") + perc <- ifelse(perc >= 1, as.character(round(perc,round)), "< 1")# add rounding option to adjust precision of percentage perc <- sapply(perc[!is.na(perc)], function(x) paste0(x, " %")) }