6

I am using the gt package to make a table ad saving it as an .RTF. I'm using the function gt::gtsave() but the table saved looks very different from what is in my viewer or outputs to HTML.

Lin: to documentation I am using https://gt.rstudio.com/reference/gtsave.html

Here is the table I am making

library(gt)
library(tidyverse)
library(glue)

# Define the start and end dates for the data range
start_date <- "2010-06-07"
end_date <- "2010-06-14"

# Create a gt table based on preprocessed
# `sp500` table data
tab <- sp500 %>%
  filter(date >= start_date & date <= end_date) %>%
  select(-adj_close) %>%
  gt() %>%
  tab_header(
    title = "S&P 500",
    subtitle = glue("{start_date} to {end_date}")
  ) %>%
  fmt_date(
    columns = date,
    date_style = 3
  ) %>%
  fmt_currency(
    columns = c(open, high, low, close),
    currency = "USD"
  ) %>%
  fmt_number(
    columns = volume,
    suffixing = TRUE
  )

And here is it appears in my viewer or when using gtsave(tab,"tab.html")

enter image description here

But when I do

gtsave(tab,"tab.rtf")

This is the output: As you can see the table has cell borders on the left and right side and the spacing is not the same. Any idea why this is? Is it possible to export .rtf and keep the table the exact same as the viewer/html? enter image description here

Daniel D. Sjoberg
  • 8,820
  • 2
  • 12
  • 28
RL_Pug
  • 697
  • 7
  • 30
  • 1
    You might try `huxtable::to_rtf()` as an alternative. The huxtable package has many options to customize table format, and most work in rtf output. – dash2 May 20 '22 at 08:31
  • 3
    I find this really frustrating about `gt`. I could not find a description of the status of `gtsave` but I believe it is simply not ready. HTML works fine and seems to be the priority. But for PDF and RTF output, most styling option do not work in my experience. – JBGruber May 20 '22 at 14:07

0 Answers0