0

How can I save a huxtable to a file in LaTeX (.tex) format? I did find this code to print LaTeX tables to the console:

library(huxtable)
ht <- huxtable(
        a = 1:3,
        b = letters[1:3]
      )
print_latex(ht)

Does the huxtable package have a native way to save the table to disk or do we need a workaround?

captain
  • 543
  • 1
  • 3
  • 20

2 Answers2

2

There might be other ways but using capture.output works -

library(huxtable)
capture.output(print_latex(ht), file = 'output.tex')
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
2

The huxtable package has a function to do that: quick_latex(ht, file = "Table.tex", open = FALSE).

captain
  • 543
  • 1
  • 3
  • 20
  • NB the difference with the other answer. `quick_latex()` prints an entire tex document. `to_latex()` or `to_latex()` just print the tex for the table itself – dash2 Aug 12 '21 at 15:02