使用 R 从 rMarkDown 文件生成 .pdf

问题描述

这是我第一次尝试使用 r 和 RStudio 生成报告。当我使用 RStudio 和 knitr 按钮以 html 格式创建文档时,过程完成得很好,没有错误。但是,当我尝试将文档设为 .pdf 时,会出现错误

要从 rmarkdown 文件创建 .pdf 文档,我已经安装了 rmarkdown、knitr、tinytex,我还安装了 TinyTeX(来自带有 tinytex 的 R)和 PANDOC,执行 tinytex :: pdflatex ('test.tex') 时的错误如下:


> tinytex::pdflatex('test.tex')

  Sorry,no translations available for es_ES (nor es); falling back to English.
    Make sure that you have the package "texlive-msg-translations" installed.
    (If you'd like to help translate the installer's messages,please see
    https://tug.org/texlive/doc.html#install-tl-xlate for @R_665_4045@ion.)

tlmgr update --all --self
warning: kpathsea: configuration file texmf.cnf not found in these directories: ...
  Sorry,please see
    https://tug.org/texlive/doc.html#install-tl-xlate for @R_665_4045@ion.)

tlmgr.pl: package repository https://ctan.math.illinois.edu/systems/texlive/tlnet (not verified: gpg unavailable)
tlmgr.pl install: package already present: kpathsea

  Sorry,please see
    https://tug.org/texlive/doc.html#install-tl-xlate for @R_665_4045@ion.)

! warning: kpathsea: configuration file texmf.cnf not found in these directories: ...
! ...éCarlos\AppData\Roaming\TinyTeX\bin\win32\runscript.tlu:935: ...éCarlos\AppData\Roaming\TinyTeX\bin\win32\runscript.tlu:858: no appropriate script or program found: fmtutil
! Running the command C:\Users\Jos<e9>Carlos\AppData\Roaming\TinyTeX\bin\win32\fmtutil-user.exe

! ...éCarlos\AppData\Roaming\TinyTeX\bin\win32\runscript.tlu:935: ...éCarlos\AppData\Roaming\TinyTeX\bin\win32\runscript.tlu:858: no appropriate script or program found: fmtutil
! Running the command C:\Users\Jos<e9>Carlos\AppData\Roaming\TinyTeX\bin\win32\fmtutil-user.exe

! Running the command C:\Users\Jos<e9>Carlos\AppData\Roaming\TinyTeX\bin\win32\fmtutil-user.exe

! kpathsea: Running mktexfmt pdflatex.fmt

! The command name is C:\Users\Jos<e9>Carlos\AppData\Roaming\TinyTeX\bin\win32\mktexfmt
! warning: kpathsea: mktexfmt output `c:/Users/Jos<e9>Carlos/AppData/Roaming/TinyTeX/texmf-var/web2c/pdftex/pdflatex.fmt' instead of a filename.

! warning: kpathsea: mktexfmt output `c:/Users/Jos<e9>Carlos/AppData/Roaming/TinyTeX/texmf-var/web2c/pdftex/pdflatex.fmt' instead of a filename.

! warning: kpathsea: configuration file texmf.cnf not found in these directories: ...
! ...éCarlos\AppData\Roaming\TinyTeX\bin\win32\runscript.tlu:935: ...éCarlos\AppData\Roaming\TinyTeX\bin\win32\runscript.tlu:858: no appropriate script or program found: fmtutil
! Running the command C:\Users\Jos<e9>Carlos\AppData\Roaming\TinyTeX\bin\win32\fmtutil-user.exe

! ...éCarlos\AppData\Roaming\TinyTeX\bin\win32\runscript.tlu:935: ...éCarlos\AppData\Roaming\TinyTeX\bin\win32\runscript.tlu:858: no appropriate script or program found: fmtutil
! Running the command C:\Users\Jos<e9>Carlos\AppData\Roaming\TinyTeX\bin\win32\fmtutil-user.exe

! Running the command C:\Users\Jos<e9>Carlos\AppData\Roaming\TinyTeX\bin\win32\fmtutil-user.exe

! kpathsea: Running mktexfmt pdflatex.fmt

! The command name is C:\Users\Jos<e9>Carlos\AppData\Roaming\TinyTeX\bin\win32\mktexfmt

! warning: kpathsea: mktexfmt output `c:/Users/Jos<e9>Carlos/AppData/Roaming/TinyTeX/texmf-var/web2c/pdftex/pdflatex.fmt' instead of a filename.

Error: LaTeX Failed to compile test.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See test.log for more info.
Además: Warning messages:
1: In xfun::read_utf8(f2) :
  The file C:\Users\JOSCAR~1\AppData\Local\Temp\RtmpKW4Z5j\stderr1f3c1e9738a0 is not encoded in UTF-8. These lines contain invalid UTF-8 characters: 1,3,7,8
2: In xfun::read_utf8(f2) :
  The file C:\Users\JOSCAR~1\AppData\Local\Temp\RtmpKW4Z5j\stderr1f3c1d92194c is not encoded in UTF-8. These lines contain invalid UTF-8 characters: 1,8
> tinytex::xelatex('test.tex')

升级 1

从 RStudio knitr / knitr 运行到 PDF,生成一个 .log 文件


! warning: kpathsea: configuration file texmf.cnf not found in these directories: ...
! ...éCarlos\AppData\Roaming\TinyTeX\bin\win32\runscript.tlu:935: ...éCarlos\AppData\Roaming\TinyTeX\bin\win32\runscript.tlu:858: no appropriate script or program found: fmtutil
! Running the command C:\Users\Jos<e9>Carlos\AppData\Roaming\TinyTeX\bin\win32\fmtutil-user.exe

! kpathsea: Running mktexfmt pdflatex.fmt

! The command name is C:\Users\Jos<e9>Carlos\AppData\Roaming\TinyTeX\bin\win32\mktexfmt
! warning: kpathsea: mktexfmt output `c:/Users/Jos<e9>Carlos/AppData/Roaming/TinyTeX/texmf-var/web2c/pdftex/pdflatex.fmt' instead of a filename.

! warning: kpathsea: configuration file texmf.cnf not found in these directories: ... ...éCarlos\AppData\Roaming\TinyTeX\bin\win32\runscript.tlu:858: no appropriate script or program found: fmtutil
! Running the command C:\Users\Jos<e9>Carlos\AppData\Roaming\TinyTeX\bin\win32\fmtutil-user.exe

! kpathsea: Running mktexfmt pdflatex.fmt

! The command name is C:\Users\Jos<e9>Carlos\AppData\Roaming\TinyTeX\bin\win32\mktexfmt
! warning: kpathsea: mktexfmt output `c:/Users/Jos<e9>Carlos/AppData/Roaming/TinyTeX/texmf-var/web2c/pdftex/pdflatex.fmt' instead of a filename.

升级 2

使用 rmarkdown::render("esfuerzo local social EELL.rmd","pdf_document") 运行,结果相同,.log 文件内容相同。

另外,我展示了回溯结果

Error: LaTeX Failed to compile esfuerzo-local-social-EELL.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See esfuerzo-local-social-EELL.log for more info.
12. stop(e," See ",logfile," for more info.",call. = FALSE)
11. show_latex_error(file,logfile)
10. on_error()
9. system2_quiet(engine,c("-halt-on-error","-interaction=batchmode",engine_args,shQuote(file)),error = { if (install_packages) tlmgr_update(run_fmtutil = FALSE,.quiet = TRUE) ...
8. run_engine()
7. on_error()
6. system2_quiet(engine,.quiet = TRUE) ...
5. run_engine()
4. latexmk_emu(file,engine,bib_engine,min_times,max_times,install_packages,clean)
3. tinytex::latexmk(file,if (biblatex) "biber" else "bibtex")
2. latexmk(texfile,output_format$pandoc$latex_engine,"--biblatex" %in% output_format$pandoc$args)
1. rmarkdown::render("esfuerzo local social EELL.rmd","pdf_document")

R version 4.0.5 (2021-03-31) -- "Shake and Throw"
copyright (C) 2021 The R Foundation for Statistical Computing
Platform: i386-w64-mingw32/i386 (32-bit)

升级 3

用 RStudio 文件/新文件/R Markdown 和 knitr/knitr 生成一个基本文档到 PDF 按钮错误是一样的,这里是 .log 文件


! warning: kpathsea: configuration file texmf.cnf not found in these directories: ...! ...éCarlos\AppData\Roaming\TinyTeX\bin\win32\runscript.tlu:935: ...éCarlos\AppData\Roaming\TinyTeX\bin\win32\runscript.tlu:858: no appropriate script or program found: fmtutil
! Running the command C:\Users\Jos<e9>Carlos\AppData\Roaming\TinyTeX\bin\win32\fmtutil-user.exe

! kpathsea: Running mktexfmt pdflatex.fmt

! The command name is C:\Users\Jos<e9>Carlos\AppData\Roaming\TinyTeX\bin\win32\mktexfmt
! warning: kpathsea: mktexfmt output `c:/Users/Jos<e9>Carlos/AppData/Roaming/TinyTeX/texmf-var/web2c/pdftex/pdflatex.fmt' instead of a filename.

! warning: kpathsea: configuration file texmf.cnf not found in these directories: ...! ...éCarlos\AppData\Roaming\TinyTeX\bin\win32\runscript.tlu:935: ...éCarlos\AppData\Roaming\TinyTeX\bin\win32\runscript.tlu:858: no appropriate script or program found: fmtutil
! Running the command C:\Users\Jos<e9>Carlos\AppData\Roaming\TinyTeX\bin\win32\fmtutil-user.exe

! kpathsea: Running mktexfmt pdflatex.fmt

! The command name is C:\Users\Jos<e9>Carlos\AppData\Roaming\TinyTeX\bin\win32\mktexfmt
! warning: kpathsea: mktexfmt output `c:/Users/Jos<e9>Carlos/AppData/Roaming/TinyTeX/texmf-var/web2c/pdftex/pdflatex.fmt' instead of a filename.


test.Rmd

```

---
title: "test"
author: "José Carlos"
date: "21/5/2021"
output:
  pdf_document: default
  html_document: default
---

```{r setup,include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown

This is an R Markdown document. Markdown is a simple formatting Syntax for authoring HTML,PDF,and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r cars}
summary(cars)
```

## Including Plots

You can also embed plots,for example:

```{r pressure,echo=FALSE}
plot(pressure)
```

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

```

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)