I am unable to weave a document containing LaTeX and R code using RStudio due what I think are TeX capacity limitations. Is there a way of fixing this without having to compile using LuaLaTeX which is not supported by knitr? I'd like the document to be as portable as possible. Below is a minimal code chunk (without actual data):

<<MyPlot, echo=FALSE, eval=TRUE, warning=FALSE, cache=TRUE, 

cbPalette <- c("#009E73", "#CC79A7")
pd <- position_dodge(0.4)

plot1<-ggplot(data=summary, aes(x=label, y=V10, colour=Adv, group=Adv)) +
  scale_colour_manual(values=cbPalette) +
  geom_errorbar(aes(ymin=V10-ci, ymax=V10+ci), width=.6, position=pd) +
  geom_line(position=pd, size = 1) +
  geom_point(position=pd, size = 3) +
  theme_bw() +
  theme(axis.text = element_text(size = 15)) +
  theme(axis.title = element_text(size = 25)) +
  theme(text = element_text(size = 20)) +
  theme(plot.margin=unit(c(0,0,0,0),"mm")) +
  theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1)) +
  ylab("My y axis") + 
  xlab("My x axis") + 
  theme(legend.justification=c(0,1), legend.position=c(0,1)) +
  theme(plot.margin = unit(c(0.2,0.2,0.2,0.2), "cm")) +
  facet_grid(. ~ scale) +

The error message I get when I compile the pdf is:

TeX capacity exceeded, sorry [parameter stack size=10000]

If I leave out the last line of the code above and do not require the plot to be printed, the code runs just fine.

  • I can't run your code but using that much parameter stack almost always implies a loop so using a bigger tex wouldn't help, is c("#009E73", "#CC79A7") valid or do you need c("\#009E73", "\#CC79A7") as you would if typesetting those strings directly in TeX? – David Carlisle May 13 '18 at 17:47
  • I am not sure I follow, the list of color hues is R code, it would never run directly in TeX. I tried running the R code with the default color options, but I get the same error. – Helena May 13 '18 at 20:24
  • 1
    Does the R part of your document run/work in R alone (without any LaTeX stuff)? This is to make sure that your R code isn't the problem. – Dr. Manuel Kuehner May 14 '18 at 7:15
  • Yes, I checked that and it works fine. There is no problem with the R code. Also, I can compile the Rnw document just fine if I comment the last line of the code above. – Helena May 14 '18 at 14:32
  • You might check if the image file for the plot you generate can be opened (in the folder figure look for MyPlot.pdf). You could also try to add the option dev='png' in the <<MyPlot, ...>>= heading see if that changes anything... – Luc M May 14 '18 at 21:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.