How can I prevent scientific notation in huxtable table footnotes?

I’m having trouble with the huxtable package in R. I want to add a footnote with a year (1776) to my table. But the year shows up in scientific notation instead of a regular number. 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 cars in 1776")

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

I also tried putting the year in quotes, but that caused an error. Does anyone know how to make the year show up normally in the footnote? Any help would be great!

I’ve encountered this issue before, and it can be frustrating. One workaround I’ve found effective is to use the paste0() function in combination with as.character(). Here’s what worked for me:

add_footnote(my_table, paste0('No cars in ', as.character(1776)))

This bypasses the numeric formatting entirely by converting the year to a string before it’s added to the footnote. It’s not the most elegant solution, but it gets the job done without messing with global options or affecting the rest of your table formatting.

Another approach, if you’re open to it, is using the kableExtra package instead. It tends to handle these edge cases more smoothly in my experience. Just a thought if you’re not wedded to huxtable for this particular project.

I’ve dealt with similar issues when working with R tables. One solution that’s worked well for me is using the prettyNum() function. It gives you more control over number formatting without affecting the rest of your table. Try this:

add_footnote(my_table, paste0('No cars in ', prettyNum(1776, big.mark = ',', scientific = FALSE)))

This approach not only prevents scientific notation but also allows you to add thousands separators if needed. It’s particularly useful when dealing with larger numbers in footnotes or table cells.

If that doesn’t solve it, you might want to check if there’s a specific setting in huxtable that’s overriding your global options. Sometimes package-specific settings can trump general R options.

hey, i’ve run into this too. have u tried using format() inside the footnote? like this:

add_footnote(my_table, sprintf(‘No cars in %s’, format(1776, scientific = FALSE)))

that might do the trick. let me kno if it works!