I´ve been trying to get the minimal Demofile for knitr running and compiling in TeXstudio, but I keep getting errormessages.

Here´s the info, mybe somebody can help me out about what I´m doing wrong:

I´m compiling this example file from the knitr website:



Here is a code chunk.

<<foo, fig.height=4>>=
chartr('xie', 'XIE', c('xie yihui', 'Yihui Xie'))
par(mar=c(4, 4, .2, .2)); plot(rnorm(100))

You can also write inline expressions, e.g. $\pi=\Sexpr{pi}$, and \Sexpr{1.598673e8} is a big number.


I have this added in my Builds as a user command in TeXstudio:

knitr:knitr   "C:/Program Files/R/R-3.0.2/bin/Rscript.exe" -e "library(knitr, lib.loc='C:/Users/User/Documents/R/win-library/3.0'); knit2pdf('%.Rnw')"

(based on the info here http://yihui.name/knitr/demo/editors/#comment-784855735 and here http://yihui.name/knitr/demo/editors/ )

Now when compiling I get the error

Couldn´t start Build & View:PdfLaTeX:"C:Program Files (x86)/MikTeX 2.9/miktex/bin/pdflatex.exe" -synctex=1 - interaction=nonstopmode "002-minimal".tex .

and when I hit Ok, it says:

Logfile not found!

TeXstudio works fine with simple .tex-documents. So what am I missing here?

Thanks in advance!

  • 1
    first, you have to put R in the PATH of your OS – Yihui Xie Oct 14 '13 at 5:23
  • Hey Yihui, first thanks for the great package, helps a lot! Secondly: thanks, it worked! Was really happy about it. Interestingly enough there was a little tweak to it: Under Windows 7 you can change the PATH variable by clicking Start -> right click Computer -> Properties -> Advanced -> Environment Variables, lower window. But when I put it there, it didn´t work, although it was correctly set. (My path to R is "C:\Program Files\R\R-3.0.2\bin\x64") But the lower solution here:link by cmd helped. Thx! – Can Oct 18 '13 at 8:19
  • Jsut a short addition: After getting it to work, I checked the PATH under Start -> right click computer... again, and although TeXstudio was now compiling Rnw, the PATH variable hadn´t changed (so no path to R included). I guess it was put somewhere else... Still works. Thanks again. – Can Oct 18 '13 at 8:23
  • @Can, +1 for this question, can u please explicitly describe your workflow in windows7 platform with MWE in more details. It didn't work, as you can only set one Path at a time and was already set to C:\texlive\2013\bin\win32, how to set it to C:\Program Files\R\R-3.0.2\bin\i386 instead?. Doest this work for XeLaTex instead of PdfLaTex? – doctorate Oct 26 '13 at 7:45
  • @ doctorate: Hi! Firstly I guess you´re in the wrong (upper) window when searchin for the path-variable (Start -> right click Computer -> Properties -> Advanced -> Environment Variables, lower window). Secondly the other solution was: Create a txtfile, that contains just this: set PATH=C:\Program Files\R\R-3.0.2\bin\x64;%PATH% where you change C:\...\x64 with the corresponding directory of your R install. Rename the txtfile to setpath.bat, then open commandline, switch to the directory (where setpath.bat is) in cmd and then put in CMD /K setpath.bat and hit enter. Should do the job. – Can Oct 28 '13 at 20:48

As can be seen in comments the solution was to add the R program folder to the system path, which corresponds to environment variable %PATH%.


install tinytex in RStudio using tinytex::install_tinytex()

tools-->global option--->Sweave
check : knitr
check : pdfLaTeX
check : Use tinytex when compiling.tex files                                          

If not work, then uninstall ur miktex in ur computer and it' will work After that reinstall miktex...

  • 1
    Welcome to TeX.SE! – Mensch Dec 22 '20 at 12:54

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.