0
votes
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(gt)
mpg.hp <- mtcars %>%
  select(mpg, hp) %>%
  gt() %>%
  cols_label(mpg = "Miles per Gallon", hp = "Horsepower") %>%
    tab_header(title = "Car Info") %>%
  cols_align(align = c("auto")) %>%
  fmt_number(columns = 1, decimals = 2) %>%
  fmt_number(columns = 2, decimals = 1)

mpg.hp

Just trying to do something basic like make a dataframe into a table and knit a PDF with that table in it via RMarkdown. It will knit as an HTML but it won't knit as a PDF unless I remove the mpg.hp call. And when I try to knit to PDF I get:

! LaTeX Error: There's no line here to end. Error: LaTeX failed to compile stackoverflow1.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See stackoverflow1.log for more info. Execution halted

I've visited the website in the Error message and followed the instructions. I've also tried using inline code to call the table, all with no success. Any suggestions?

1
I can't reproduce your error since I don't have your data. Are you able to reproduce this error using one of the datasets built into R?max
@max I've edited the original post to provide a reproducible example.DJS

1 Answers

1
votes

Apparently, there is a bug with gt which won't allow you to knit to pdf when calling tab_header() with a title but without a subtitle. I inserted a blank subtitle and that seemed to do the trick.