dfe-analytical-services / dfeR

Common R tasks in the Department for Education (DfE)
https://dfe-analytical-services.github.io/dfeR/
GNU General Public License v3.0
9 stars 2 forks source link

Make pretty_num() function handle multiple values by default #72

Open cjrace opened 2 months ago

cjrace commented 2 months ago

Is your feature request related to a problem? Please describe.

Currently we have to give examples of how to use the function with vectors, e.g.

# On individual values
pretty_num(5789, gbp = TRUE)
pretty_num(564, prefix = "+/-")

# Applied over an example vector
vector <- c(3998098008, -123421421, "c", "x")
unlist(lapply(vector, pretty_num))
unlist(lapply(vector, pretty_num, prefix = "+/-", gbp = TRUE))

Describe the solution you'd like

Ability for the value argument to take a vector so that in the above example you could just do this instead:

# Applied over an example vector
vector <- c(3998098008, -123421421, "c", "x")
pretty_num(vector)
pretty_num(vector, prefix = "+/-", gbp = TRUE)

Describe alternatives you've considered

Could use other package functions or just leave as is, though it would be nice to make this function work given it's readability in code for the common ways we want to format numbers.

Additional context

We often format things like numbers in tooltips or axes of charts, these all usually come in vector form and would be made a lot neater by adapting the function to take individual numbers or vectors

jen-machin commented 3 days ago

pretty_num() updates on dfeR