'knit to PDF failure

I am an R user with 4 years of experience, but only recently starting using RMarkdown, from RStudio. Generally things have gone OK, and have been able to export my results to PDF (and also to Word and HTML, but I don't care about those. My code reads in rainfall data and then generate summary statistics and a few charts (ggplot). I installed MiKTeX and I believe RStudio uses that. Now a problem has crept in. When I knit to PDF, I get the following error:

! TeX capacity exceeded, sorry [input stack size=5000]. \LS@makecol ->\LS@makecol \LS@rot l.205 \begin{landscape}

Error: LaTeX failed to compile test-rticles-elsevier.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See test-rticles-elsevier.log for more info. In addition: Warning message: In rm(chart_title, outfile_name, PNG_folder_name, outfile) : object 'outfile' not found Execution halted

I found this answer, which suggested using the 'rticles' package and using one of the journal templates (e.g. elsevier).

R markdown / bookdown - how to switch to rticles?

I installed the 'rticles' package and gave that a try. In the YAML area I had (for the output part):

output: pdf_document: toc: no rticles::elsevier_article: citation_package: natbib keep_tex: yes

That approach initially worked and I was able to knit to PDF, but after I kept copying in my code chunks and knitting to PDF, I got the same error shown above (i.e. ! TeX capacity exceeded, sorry [input stack size=5000]. I re-booted my laptop, and tried again, but alas the same error.

I am wondering if I should consider removing MiKTeX and trying another product. Someone on SO mentioned LiveTex. Not sure where to turn at this point. Any pointers appreciated. My r setup is copied below, in case that helps.

knitr::opts_chunk$set(echo = FALSE)

library(plyr)
library(tidyverse)
# note: tidyverse includes 'dplyr' package but not 'plyr'

library(printr)
library(reshape2)
library(pander)

library(lubridate)
library(scales)
library(rio)
library(knitr)
library(tinytex)
library(ggnewscale)
library(kableExtra)
library(hydroTSM)
library(cowplot)

panderOptions('knitr.auto.asis', FALSE)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source