TeX package not installing in R version 3.1.0

17,817

Solution 1

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.)

Solution 2

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.

Solution 3

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=";"))
Share:
17,817
Admin
Author by

Admin

Updated on June 08, 2022

Comments

  • Admin
    Admin almost 2 years

    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.

  • tonytonov
    tonytonov almost 10 years
    Thanks for the hint! Very neat package, never knew it existed.
  • tonytonov
    tonytonov almost 10 years
    It is indeed for Windows only.
  • shiny
    shiny over 8 years
    @Gregor I'm having the same problem. I tried to use installr::installr(MikTeX) but it didn't work. Any suggestions would be appreciated?
  • michaelsinner
    michaelsinner over 7 years
    The TexLive pkg is nearly 3GB. Thats quite large just to make PDFs out of rStudio (Notebooks to PDF). Is there any other way? @tonytonov
  • tonytonov
    tonytonov over 7 years
    @michaelsinner See tug.org/texlive/acquire-netinstall.html : tarball is 3.3 mb.