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

Number options #453

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Number options #453

wants to merge 5 commits into from

Conversation

teunbrand
Copy link
Contributor

This PR aims to fix #376.

Briefly, it adds a new function number_options() that globally sets options for formatting numbers.
Subsequently, the label_*() functions use these options by default.

Rendered examples of the documentation:

devtools::load_all("~/packages/scales/")
#> ℹ Loading scales

# Default number formatting
x <- c(0.1, 1, 1000)
label_number()(x)
#> [1] "0.1"     "1.0"     "1 000.0"

# Now again with new options set
number_options(style_positive = "plus", decimal.mark = ",")
label_number()(x)
#> [1] "+0,1"     "+1,0"     "+1 000,0"

# The options are the argument names with a 'scales.'-prefix
options("scales.style_positive")
#> $scales.style_positive
#> [1] "plus"

# Resetting the options to their defaults
number_options()
label_number()(x)
#> [1] "0.1"     "1.0"     "1 000.0"

Created on 2024-10-03 with reprex v2.1.1

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.

Feature: global options for decimal.mark and big.mark
1 participant