Last active
December 7, 2020 23:16
-
-
Save kylebutts/c0857c7c9f176636f50f197056e63791 to your computer and use it in GitHub Desktop.
Extract Latex body from gt table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Requires gt::gt() object or gt::as_latex() object and returns just the body of the gt table | |
extract_body_gt <- function(gt) { | |
if(inherits(gt, "gt_tbl")) gt <- as.character(gt::as_latex(gt)) | |
stringr::str_match(gt, "(?s)\\\\midrule\\n(.*)\\\\bottomrule")[[2]] | |
} | |
library(tidyverse, warn.conflicts = FALSE) | |
library(gt, warn.conflicts = FALSE) | |
# HTML | |
head(mtcars) %>% | |
gt() %>% | |
gt::as_raw_html() | |
# Latex Body | |
head(mtcars) %>% | |
gt() %>% | |
extract_body_gt() %>% | |
cat() | |
# cat(., file = "*/*.tex) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requires gt::gt() object or gt::as_latex() object and returns just the body of the gt table
Created on 2020-12-07 by the reprex package (v0.3.0)