vincentarelbundock / tinytable

Simple and Customizable Tables in `R`
https://vincentarelbundock.github.io/tinytable
GNU General Public License v3.0
211 stars 18 forks source link

Print to gfm #315

Closed kylebutts closed 4 months ago

kylebutts commented 4 months ago

Running directly in the terminal:

tt(mtcars[1:4, 1:5]) |> print("gfm")
mpg cyl disp hp drat
21.0 6 160 110 3.90
21.0 6 160 110 3.90
22.8 4 108 93 3.85
21.4 6 258 110 3.08

The main thing to note is that disabling hlines makes pandoc fail to convert, so if they have the option set to false, I ignore for the duration of print and restore it afterwards.

  # Not having hlines prevents conversion to gfm, so temporarily disable this option
  if (output == "gfm") {
    has_hlines <- get_option("tinytable_markdown_hlines")
    if (isFALSE(has_hlines)) {
      options(tinytable_markdown_hlines = TRUE)
      on.exit(options(tinytable_markdown_hlines = FALSE))
    }
  }
vincentarelbundock commented 4 months ago

Thanks, I made some minor modifications (moved the pandoc call to build_tt()) and merged.

This is great!