R语言输出RMarkdown为其他格式时(如PDF)时报错LaTeX failed to compile stocks.tex.的解决办法
在使用R语言输出R Markdown为其他格式时,有时会出现以下报错LaTeX failed to compile stocks.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See Untitled.log for more info.In addition: Warning message:In syst
文章共1,088字 · 阅读需要大约4分钟
一键AI生成摘要,助你高效阅读
问答
·
Rmd输出为其他格式
(一)未安装Tinytex包导致报错
在使用R语言输出R Markdown为其他格式时,有时会出现以下报错
LaTeX failed to compile stocks.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See Untitled.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
同时,有时下面还会报错未找到某一个包,如'"tlmgr"' not found
、‘"pdflatex"' not found
等。
此时打开https://yihui.org/tinytex/r/#debugging for debugging,根据指引,你可以这样做:
- 首先安装 tinytex包(在上图的Console里面,下面的三句任意一句都可以)
install.packages('tinytex') tinytex::install_tinytex() remotes::install_github('yihui/tinytex')
- 再尝试输出一次,如果仍然无法输出,可以遵循https://yihui.org/tinytex/r/#debugging for debugging给出的以下步骤(之后每做一步都可以尝试是否可以顺利输出):
重新安装所有包update.packages(ask = FALSE, checkBuilt = TRUE) tinytex::tlmgr_update()
- 如果报错:
tlmgr: Remote repository is newer than local
,重新安装tinytex
一定要先运行1.里面的代码哦!如果一开始就运行了这行代码,会出现以下报错:tinytex::reinstall_tinytex()
#第一类 tlmgr update --all --self Error in system2("tlmgr", args, ...) : '"tlmgr"' not found #第二类 package ‘TLMGR’ is not available for this version of R #等等
- 在R Markdown 文件中加入以下字句:
{r, include=FALSE} options(tinytex.verbose = TRUE)
(二)Rmd可以输出为其他格式,无法输出为PDF:
此时会产生以下报错:
! Package inputenc Error: Unicode character ?(U+6CF0)
(inputenc) not set up for use with LaTeX.
Try other LaTeX engines instead (e.g., xelatex) if you are using pdflatex. For R Markdown users, see https://bookdown.org/yihui/rmarkdown/pdf-document.html
错误: Failed to compile a.tex. See https://yihui.name/tinytex/r/#debugging for debugging tips. See a.log for more info.
此外: Warning message:
In grepl("==> Fatal error occurred", x[i], fixed = TRUE) :
输入的字符串1不适用于此语言环境
停止执行
- 点击设置button,选择output options。
- Output选择为PDF后点击Advanced
- 更改LaTeX engine 为xelatex后点击OK
也可以直接在文件头部加入以下代码后输出。
output:
pdf_document:
latex_engine: xelatex
来源:https://stackoverflow.com/questions/32794157/package-inputenc-error-unicode-char-u8-in-rstudio
有其他问题欢迎评论探讨~
更多推荐
已为社区贡献1条内容
所有评论(0)