pdf failed to compile from .Rmd

I'm trying to knit a pdf from a particular .Rmd file but it is not rendering. I can knit to pdf for some other .Rmd files but not this one. I'm on Linux, all packages are updated, tinytex is installed, as well as texlive.

Any ideas? Here is the error:

output file: XXXX.knit.md

! Undefined control sequence.
l.476   Inserting \(\n
                      \) into {[}most{]} text strings will provide a 

Error: LaTeX failed to compile XXXX.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See XXXX.log for more info.
In addition: There were 23 warnings (use warnings() to see them)
Execution halted

Is this possible to share the Rmd file ?

It seems there is an issue with a syntax somewhere, and with only the log file it will be difficult.

If you can't share,trying to build a reprex will help.
Error seems to be in l.476 of your tex file. :thinking:

Hmm. I can't attach an .Rmd file- not allowed and it's too long to paste all in a code block. So I'll paste the block containing line 476 (though I can't see an issue in that line of code? 476 begins: plot(density(rnorm(100000)...:

```{R, results='hide', echo = FALSE}
colors <- colorblind_pal()(8)
moment <- c(1,2,3,4,5,10,15,20)
layout(mat = matrix(c(1,1,1,1,2,3,4,5,6,7,8,9,10,10,10,10), nrow = 4, ncol = 4, byrow = TRUE),
                  heights = c(.75,2.25,2.25,1)
   )
par(mar=c(0,0,4,0))
plot.new()
title(main =expression(paste('Probability density function of normal distributions \nMoments: mu (',mu ,"), ", "sigma (",sigma,")",sep = '')), cex = 2)
par(mar=c(4,4,1,1))
lapply(c(1:8), FUN = function(i){
plot(density(rnorm(100000 , mean = 0, sd = moment[i])), col = colors[i], ylim = c(0,.4), xlim = c(-5*moment[i],5*moment[i]), pch=16, ylab = "Density", xlab = "x",
     main = "")
})
par(mar=c(1,1,1,1))
plot.new()
legend('bottom', legend = moment, fill= colorblind_pal()(6), title = expression(paste('mu (', mu ,")", sep = "")), cex=1, horiz = TRUE)

Problem solved. I had this test in the .Rmd file which was interpreted as a control character: \n

I just needed to look harder :-]

1 Like

If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.