gt table in R Markdown not being outputted

Viewed 580

I just discovered the gt library and was excited to try it out but no matter what I did, the tables keep being outputted as a function???

The code is the same on the homepage of the gt website, the gt(x) is literally being processed as a function as we can see from the picture. I updated all my packages and even installed the developer version as well but I keep getting this function output gt table function output, no table

2 Answers

You can use the gtsave function and save as a .png and it will output. For example, here is a plot that I generated with the following code:

{r mOS Table Generation, fig.dim=c(6,8)}
mostable <- mosdf %>%
  ungroup %>%
  select(-Dose) %>%
  gt() %>%
  tab_header(title = "Median Overall Survival (mOS)", subtitle = md("*Subjects Treated from REDACTED*")) %>%
  tab_spanner(
    label = "95% Confidence Interval",
    columns = c(5:6)) %>%
  cols_align(align = "center") %>%
  tab_style(cell_text(weight = "bold"),
            locations = list(cells_title(groups = c("title", "subtitle")), 
                             cells_column_spanners(spanners = everything()), 
                             cells_column_labels(columns = c(1:4)))) %>%
  tab_style(cell_text(style = "italic"),
            locations = cells_row_groups(groups = everything()))

setwd(output)
gtsave(mostable, "mostable.png", vwidth = 1500, vheight = 1000)

Here is how it looks the R Markdown when knitted to Word:

gtsaveexample

Note, even though I have the dimension statement in the chunk code, gtsave is dependent on webshot, so the vwidth and vheight control the size of the output to the working directory. Most of the time the output size is fine, but I am still working through how to change the output size. Most of the time I just manually do it, but prefer to not have to update the output. I am going to ask another question, so I will link if there is a solution.

My apologies, turns out there's also a function called "gt" in the expss package I had loaded that interfered with it, looks like I'm not getting my hour back from trying to troubleshoot this lol

Related