'Export mmtable from R
I am trying to export a generated mmtable either as .png or directly to the word. I have already tried saveWidget and webshot. But any attempt is without success. Do you have any advice on how to export a mmtable, please?
library(mmtable2)
library(gt)
library(tidyverse)
1.0 Data Transformation -----
data_wrangled <- mpg %>%
group_by(manufacturer, cyl) %>%
summarise(across(.cols = c(cty, hwy), .fns = mean)) %>%
ungroup() %>%
pivot_longer(
cols = c(cty, hwy),
names_to = "fuel_economy_type",
values_to = "fuel_economy"
)
data_wrangled
2.0 Table Main ----
main_table <- data_wrangled %>%
mutate(fuel_economy = round(fuel_economy, 1)) %>%
mmtable(cells = fuel_economy, table_name = "Fuel Economy") +
# Specify Headers
header_top(manufacturer) +
header_left(cyl) +
header_left_top(fuel_economy_type) +
# Specify formatting
header_format(manufacturer, list(cell_text(transform = "capitalize"))) +
header_format(fuel_economy_type, list(cell_text(transform = "uppercase"))) +
table_format(
locations = list(
cells_body(rows = c(2, 6))
),
style = list(
cell_borders(sides = "top", color = "grey")
)
)
main_table
saveWidget(main_table, "temp.html")
webshot("temp.html", "main_table.png", vwidth = 441, vheight = 351)
Solution 1:[1]
You can export your mmtable2 table with the gtsave function from the gt package.
Your codes should look something like this:
gtsave(apply_formats(main_table), filename = "main_table.rtf")
or
gtsave(apply_formats(main_table), filename = "main_table.png")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ian |
