Huxtable footnote displays 4-digit year in exponential format instead of regular numbers

I’m having trouble with the huxtable package in R. When I try to put a year like 2023 in a table footnote, it shows up as scientific notation instead of the normal number format.

Here’s what I’m doing:

options(scipen = 999)
library(huxtable)
my_table <- huxtable(iris[1:3, 1:2])
number_format(my_table) <- 0
add_footnote(my_table, "Data collected in 2023")

But the footnote comes out as:

# Data collected in 2.02e+03

I thought setting number_format() would fix this for the entire table including footnotes, but it only seems to work for the table data itself. When I don’t set the number format, the whole table goes back to scientific notation which I don’t want either.

I also tried putting the year in quotes but that gave me a syntax error. Has anyone figured out how to make footnotes display regular numbers instead of exponential format?

Here’s another workaround - use sprintf() for better control over number formatting in footnotes. Try add_footnote(my_table, sprintf("Data collected in %d", 2023)) to force integer display no matter what your global formatting settings are. I ran into this same issue with sample sizes and participant counts that kept switching to scientific notation. sprintf() gives you way more flexibility than as.character() since you can specify exactly how numbers should look - %d for integers, %.0f for rounded decimals, whatever you need. Works consistently across different huxtable versions and won’t mess with your table’s main number formatting.

totally agree! as.character() is a lifesaver for this kind of stuff. +1 for using paste() to string things together. it really makes your footnote look cleaner!

Had this exact problem last month with quarterly reports. Huxtable treats any number in footnotes as something to format, even when it’s just part of regular text. Here’s what fixed it for me: wrap the year in as.character() before adding it to the footnote. Try add_footnote(my_table, paste("Data collected in", as.character(2023))) instead. This makes R treat 2023 as text, not a number that needs formatting. I’ve used this fix for months now - works great for years, IDs, and any numeric identifiers without triggering scientific notation.