Rstudio won't knit my Rmd file

Whenever I try to knit on R I get this error

processing file: rmkdfile.Rmd
|.......... | 14%
ordinary text without R code

|.................... | 29%
label: setup (with options)
List of 1
$ include: logi FALSE

|.............................. | 43%
ordinary text without R code

|........................................ | 57%
label: cars
|.................................................. | 71%
ordinary text without R code

|............................................................ | 86%
label: pressure (with options)
List of 1
$ echo: logi FALSE

|......................................................................| 100%
ordinary text without R code

/private/var/folders/dh/y2pg6bw54xq1by18cx81z8t40000gn/T/AppTranslocation/07777596-15E8-44F3-AD90-2E6EDF8CC52F/d/RStudio.app/Contents/MacOS/pandoc/pandoc +RTS -K512m -RTS rmkdfile.knit.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output rmkdfile.tex --lua-filter /Library/Frameworks/R.framework/Versions/4.1/Resources/library/rmarkdown/rmarkdown/lua/pagebreak.lua --lua-filter /Library/Frameworks/R.framework/Versions/4.1/Resources/library/rmarkdown/rmarkdown/lua/latex-div.lua --self-contained --highlight-style tango --pdf-engine pdflatex --variable graphics --variable 'geometry:margin=1in'
output file: rmkdfile.knit.md

! sh: pdflatex: command not found

Error: LaTeX failed to compile rmkdfile.tex. See The R package tinytex - Helper Functions to Manage TinyTeX, and Compile LaTeX Documents - Yihui Xie | 谢益辉 for debugging tips. See rmkdfile.log for more info.
In addition: Warning message:
In system2(..., stdout = if (use_file_stdout()) f1 else FALSE, stderr = f2) :
error in running command
Execution halted

No LaTeX installation detected (LaTeX is required to create PDF output). You should install a LaTeX distribution for your platform: Get LaTeX - Mac OS, Windows, Linux

The last paragraph tells you all. Therefore install a LaTeX version.
Read https://yihui.org/tinytex/#for-r-users

I have the tinytex package installed and loaded, I have tried restarting but I still get the same error

Then it looks like the LaTeX install has not been done correctly.
I can't help you with that.
For other forum members to be able to help you it is necessary to specify the details of your R environment.
E.g. share the result of sessionInfo after loading rmarkdown :

library(rmarkdown) 
sessionInfo()

Good luck!

The error message refers to a LaTeX distribution (like TinyTeX) not to the tinytex package, besides installing the package, you need to install the TinyTex LaTeX distribution, you can do it with this command:

tinytex::install_tinytex()
3 Likes

Documentation about install LaTeX using TinyTeX distribution through tinytex package is there:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.