如何在R中设置sweave的乳胶路径?

时间:2015-11-11 12:48:00

标签: r rstudio knitr sweave pdflatex

我想知道如何在onchange中设置pdflatex路径以使用R。因为我有两个不同的MikTeX安装,一个正常工作。请考虑我在sweave中使用R(RStudio)。但是,我发现了一些针对Linux或Unix用户的建议。

提前致谢

1 个答案:

答案 0 :(得分:10)

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:

  1. 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.
  2. 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").
  3. add a line to the environment file as follows: PATH=C:\\full\\path\\to\\the\\folder\\with\\pdflatex;"${PATH}" (the quotations marks are important)
  4. 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")).