compiling minimal knitr example fails
Asked Answered
L

1

11

I'm working on getting knitr setup. I installed the latest version of R (2.15.1), Lyx 2.0 including the MiKTex 2.9 distribution, and RStudio 0.96.304 on a Windows 7 Enterprise box. I can get pdflatex output if I open up Lyx and simply view the tutorial, so the basic system is working. I then downloaded the minimal Rnw example saved it in my working directory as testknitr.Snw, opened that file in RStudio, and pressed the compile PDF button. The knitr output completes with a single warning about the parser package, and produces a file testknitr.tex. pdflatex.exe then runs, but fails, and the particular error in the log file seems to be

 ! LaTeX Error: Environment alltt undefined.  

I received the same error when attempting to compile testknitr.tex using TexWorks. I created that file from inside R using knit("testknitr.Rnw") - different extension because of the default in RStudio. I did tell MikTek to update packages automatically when compiling. A bit of research on CTAN suggests that the alltt environment is part of the ltxbase package, which is installed when I look at the package manager. In fact it seems like a pretty core part of the whole thing!

OK - I was reading the comments on the minimal example page, and discovered a workaround to that problem, and that it is a known bug as of 19 hours ago. And yes, I doublechecked that RStudio is set to use knitr, not sweave. I now get a new error:

! LaTeX Error: Command \textquotesingle unavailable in encoding T1. 

EDIT: OK! it turns out that error isn't fatal - there's a lovely pdf of the minimal example sitting in the working directory if one takes the time to look. Somewhat alarming that RStudio thinks compilation failed when it didn't?

Leonialeonid answered 27/6, 2012 at 19:50 Comment(5)
The workaround, perhaps obvious to an experienced LaTex-ie, is to add \usepackage{alltt} to the file. According to Yihui's comment this will be fixed in future versions, or now if you get the development version of knitr.Leonialeonid
Could you add this as an answer and accept it? In that way people can see it has been answered, and you can get some rep :)Viperish
Thanks, @Leonialeonid It seems I need to push a new version to CRAN before more people get confused, but CRAN people will yell at me for updating too frequently... BTW, I cannot reproduce the textquotesingle error under Ubuntu/TeXLive, but I guess you can comment out \usepackage[T1]{fontenc}.Gearldinegearshift
@PaulHiemstra I tried - but until you have 10 rep you can't answer your own question in less than 8 hours! I'm 4 points short (thank you to whoever upvoted the question!) ...Leonialeonid
Then we'll see the answer in a few hours :). In addition, I upvoted you, you really made an effort in writing a good question.Viperish
L
9

The workaround, perhaps obvious to an experience LaTex-ie, is to add

\usepackage{alltt}

to the file. According to Yihui's comment this will be fixed in future versions, or now if you want to get the development version from github. I also tested @Yihui's comment above that the line

\usepackage[T1]{fontenc}

could be commented out. This fixes the 2nd issue in the question, and RStudio now treats the compilation as successful, cleaning up (some?) intermediate files and immediately previewing the pdf.

Leonialeonid answered 28/6, 2012 at 1:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.