Huxtable package: How to prevent scientific notation in table footnote years?

I’m having trouble with the huxtable package in R. I want to add a footnote with a 4-digit year to my table, but it keeps showing up in scientific notation. Here’s what I’ve tried:

options(scipen = 100, digits = 10)
library(huxtable)
my_table <- huxtable(mtcars[1:5, 1:2])
number_format(my_table) <- 1
add_footnote(my_table, "No automobiles in 1776")

The footnote comes out as “No automobiles in 1.78e+03”. I thought setting number_format() would fix this, but it doesn’t seem to work for footnotes. If I remove that line, the whole table goes back to scientific notation.

I also tried putting the year in quotes, but that just gives me an error. Does anyone know how to keep the year as a regular number in the footnote? Any help would be great!

hey sparklingGem, had similar issues. try this: add_footnote(my_table, “No automobiles in \num{1776}”). the \num{} macro forces it to display as a regular number. worked for me! lmk if it helps or if u need more info

I’ve run into this exact issue before with huxtable, and it can be frustrating! The trick I found is to use the escape_contents parameter when adding the footnote. Here’s what worked for me:

add_footnote(my_table, 'No automobiles in 1776', escape_contents = FALSE)

This tells huxtable not to treat the footnote text as a number that needs formatting. It should display the year as-is.

Another approach that sometimes helps is to force the year to be treated as text by adding a space after it:

add_footnote(my_table, 'No automobiles in 1776 ')

The trailing space prevents R from interpreting it as a number. Just make sure to adjust your text accordingly if you use this method.

Hope this helps solve your issue! Let me know if you need any clarification.

I’ve encountered this problem with huxtable as well. A workaround I’ve found effective is to wrap the year in backticks within the footnote text. This treats it as inline code, preventing any automatic formatting:

add_footnote(my_table, "No automobiles in `1776`")

This method preserves the original number format without resorting to escape_contents, which can sometimes cause issues with other formatting in complex tables.

Another option is to use a Unicode non-breaking space before the year:

add_footnote(my_table, paste0("No automobiles in ", "\u00A0", "1776"))

This keeps the year intact while maintaining a clean appearance in the footnote.