I would like to know how I can set the pdflatex path in R
to use sweave
. Because I have 2 different MikTeX installations and one is working properly. Please take into account that I am using R (RStudio) in Windows
. I found some suggestion however, for Linux or Unix users.
thanks in advance
If you have multiple installs of LaTeX (i.e. MikTeX) and you want to use a specific one of these, then you need to make sure that R finds the one you need first. This means that you have to add the location of your preferred version of pdfLaTeX at the front of your PATH system environment variable.
If you do not have administrator rights in Windows, then you can use R's environment file to change the PATH variable for R only. See ?Startup
in R for details on this process. Follow the following steps:
- in R, check the output of
Sys.getenv("R_ENVIRON")
. This will return the full path to an existing environment file, but will be empty in most cases. If a file exists, skip to step 3 below.
- if no path is returned in step 1, create a file Renviron.site in the folder R_HOME/etc where R_HOME is the path returned by `Sys.getenv("R_HOME").
- add a line to the environment file as follows:
PATH=C:\\full\\path\\to\\the\\folder\\with\\pdflatex;"${PATH}"
(the quotations marks are important)
- restart R and check
Sys.getenv("PATH")
and Sys.which("pdflatex")
returns the correct paths.
If you do not have rights to create a Renviron.site file in R_HOME\etc, then you can also create a .Renviron file in HOME (Sys.getenv("HOME")
).