I am getting an error when using the summary() function using Knitr in Lyx. The functions preceding it works.
<<>>=
library(faraway)
head(teengamb)
mdl <- lm(gamble ~ sex + status, data=teengamb)
summary(mdl)
@
I am inputing this code through Insert Tex Code in Lyx. I just tested I can run summary(teengamb) but not summary(mdl). Both codes work in RStudio.
The error is "Undefined Control Sequence" with description "\end{verbatim} ..."
This problem has been solved in
knitr
after version 1.1. You do not need to change anything in LyX or R. For now, you can install the development version from:Please ignore both answers below:
I have finally found out the reason for this error (this is the deepest bug I have ever seen). It is because the
upquote
package does not work if theT1
encoding is declared after it is loaded, e.g.But if we move
upquote
afterfontenc
, it works:Or just do not use the T1 encoding -- uncheck the checkbox before the font encoding in the preferences:
The reason that Ubuntu users were not able to reproduce the problem was because
upquote.sty
was from R's texmf tree instead of the one in TeXLive, and R's version ofupquote
works.The other way to fix the problem is to add R's texmf tree to MikTeX under Windows.
Please ignore the answer below:
Since
options(show.signif.stars = FALSE)
worked, I'm posting it as one possible answer, but this is still a very weird problem to me. Settingshow.signif.stars = FALSE
removes the significance codes from the results below (which was fromsummary(mdl)
):The error came from the line
Signif. codes
, and I do not understand why any of these characters could possibly cause errors in LaTeX: all of them are ASCII and should work inside theverbatim
environment.From the comments above, neither @mrdwab nor me could reproduce the problem. I guess there must be something weird about the OP's LaTeX installation.