Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow rounding of numbers in output when quantities include "percentage" #101

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion R/setup_geometry.R
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,18 @@ 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,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
round <- ifelse(is.null(options("round")$round) != TRUE,
round <- ifelse(!is.null(options("round")$round),

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please use the eulerr_options() interface instead? https://github.com/jolars/eulerr/blob/main/R/eulerr_options.R

I don't think it would be a good idea to add just "round" to the global options. It could easily be overwritten by something else.

options("round")$round,
0)
num <- orig[centers$id[singles | others]]

if (is.null(quantities$labels)) {
type <- quantities$type

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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
perc <- ifelse(perc >= 1, as.character(round(perc,round)), "< 1")# add rounding option to adjust precision of percentage
perc <- ifelse(perc >= 1, as.character(round(perc, round)), "< 1")

perc <- sapply(perc[!is.na(perc)], function(x) paste0(x, " %"))
}

Expand Down