write_overleaf_tex.RdWrites a single value - usually a key statistic - to a .tex file in
your Overleaf project's atlas folder, ready to include in the report
with \input{atlas/filename}. Designed to sit at the end of a pipe
that pull()s out one number.
write_overleaf_tex(value, filename, accuracy = NULL, push = TRUE)A single value: a number, or text that is already formatted.
Numbers are written in full (1000000, never 1e+06) unless
you supply accuracy.
Name of the file to write in the atlas folder, with
or without the .tex extension. Can include a subfolder, such as
"stats/debt-2025".
Optional. Round a number to this accuracy before writing
it, using scales::number() with a comma between thousands - so
accuracy = 0.1 turns 1234.567 into 1,234.6. Ignored
for text. Defaults to NULL, which writes the number as it is.
Logical. Only used when your Overleaf project syncs over git.
TRUE by default, meaning the file is sent to Overleaf as soon as
it's written. Set to FALSE when writing a batch of values, then
call overleaf_push once at the end - it's quicker.
The path of the file written, invisibly.
The file ends with a %, so that LaTeX doesn't add a space
after the value: \input{atlas/debt}\% gives "3.4%", not
"3.4 %".
The value is written as it is, so text containing LaTeX special
characters needs escaping yourself. In particular a bare % would
start a LaTeX comment, so write "50\\%" rather than
"50%".
Like grattan_save_overleaf, this writes to the project set
with set_overleaf_project. If the file has been edited or
deleted in Overleaf, writing it again puts your version back.
grattan_save_overleaf to save charts the same way,
overleaf_push to send batched files to Overleaf
if (FALSE) { # \dontrun{
set_overleaf_project("https://www.overleaf.com/project/0123456789abcdef01234567")
# At the end of a pipe
mtcars %>%
summarise(mpg = mean(mpg)) %>%
pull(mpg) %>%
write_overleaf_tex("mean-mpg", accuracy = 0.1)
# Already-formatted text
write_overleaf_tex("\\$2.5 billion", "cost-total")
# Writing a batch of values: push once at the end
write_overleaf_tex(12.3, "stat-a", push = FALSE)
write_overleaf_tex(45.6, "stat-b", push = FALSE)
overleaf_push()
} # }