I am trying to generate a pdf from .Rnw file using knitr package.
Please find the output of sessioninfo()
below
R version 3.1.0 (2014-04-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] knitr_1.6
loaded via a namespace (and not attached):
[1] evaluate_0.5.5 formatR_0.10 stringr_0.6.2 tools_3.1.0
I have installed knitr but am unable to compile the code in the .Rnw file. There is a popup that is saying "No TeX installation detected. Please install TeX before compiling". However both TeX and pdfLaTeX is not installing for this version of R, a warning message comes saying that TeX or pdfLaTex is not available.
Thanks in advance.
As a convenience, the installr
R package is a very convenient way to install TeX--and a bunch of other useful stuff. Just run installr::installr()
and pick MikTeX (at least). (Not sure if it works for non-Windows.)
Wrapping my comment into an answer. knitr
uses pdflatex
to generate a pdf. pdflatex
is a part of TeX/LaTeX installation, which is not an R package and cannot be installed using R terminal (at least natively, because installr
can actually do this, as indicated by @Gregor).
You need TeX installation on your machine to work properly with knitr
. There are several options, with Miktex for Windows or TexLive for linux.
Take a look at the minimal example shipped with knitr
. It starts with \documentclass{article}
, which is a typical first line of a TeX file.
As a final note, R markdown can produce HTML using pandoc
instead, so it does not require TeX and may be a good alternative if you prefer not to use TeX/LaTeX.
Step 1: Download and Install MiKTeX from http://miktex.org/2.9/setup
Step 2: Run
Sys.getenv("PATH")
in R studio This command returns the path where Rstudio is trying to find pdflatex.exe In windows (64-bit) it should return C:\Program Files\MiKTeX 2.9\miktex\bin\x64\pdflatex.exe If pdflatex.exe is not located in this location Rstudio gives this error code 41.
Step 3: To set this path variable run:
Sys.setenv(PATH=paste(Sys.getenv("PATH"),"C:/Program Files/MiKTeX 2.9/miktex/bin/x64/",sep=";"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With