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

Conversation

xiaosongz
Copy link

#76
#75

allow round quantities("percentage") using global parameter options("round")$round.
round will be set as 0 if global parameter options("round")$round not set.

Copy link
Owner

@jolars jolars left a comment

Choose a reason for hiding this comment

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

Thanks for this PR! But see my comments. Could you also please make this work for non-percentage quantities too?

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")

@@ -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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants