grattan / grattan/grattantheme
Add function to export datapoints to Latex
Open
@ashleighchangg is already working on this.
Since Dec 11, 2025.
- Dominant language
- R
- Stars
- 24
- Forks
- 6
- Avg merge
- 30m
- Merged PRs (30d)
- 1
Description
In the process of report writing, we often export datapoints to an Overleaf atlas in .tex format. We should create a function that automates the process of reformatting those numbers for inclusion in-text. An example from Liz's previous work is below:
write_numbers_in_text <- function(number, type = c("percent", "number")) {
library(english)
library(dplyr)
library(scales)
type <- match.arg(type)
if (type == "percent") {
output <- case_when(
dplyr::between(number, 0.46, 0.54) ~ "half",
dplyr::between(number, 0.30, 0.36) ~ "a third",
dplyr::between(number, 0.64, 0.70) ~ "two thirds",
number < 0.1 ~ paste0(as.character(english::as.english(number * 100)), " per cent"), # Convert to character
TRUE ~ scales::label_percent(accuracy = 1, suffix = " per cent")(number)
)
} else {
output <- case_when(
number < 10 ~ as.character(english::as.english(number)), # Convert to character
TRUE ~ scales::comma(number)
)
}
# we do this for copying into Latex, so it comments out the extra line breaks and doesn't muck up the para
output <- paste0(output, "%")
return(output)
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.