(一)未安装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,根据指引,你可以这样做:
在这里插入图片描述

  1. 首先安装 tinytex包(在上图的Console里面,下面的三句任意一句都可以)
    install.packages('tinytex')
    tinytex::install_tinytex()
    remotes::install_github('yihui/tinytex')
    
  2. 再尝试输出一次,如果仍然无法输出,可以遵循https://yihui.org/tinytex/r/#debugging for debugging给出的以下步骤(之后每做一步都可以尝试是否可以顺利输出):
    重新安装所有包
    update.packages(ask = FALSE, checkBuilt = TRUE)
    tinytex::tlmgr_update()
    
  3. 如果报错:tlmgr: Remote repository is newer than local,重新安装tinytex
    tinytex::reinstall_tinytex()
    
    一定要先运行1.里面的代码哦!如果一开始就运行了这行代码,会出现以下报错:
    #第一类
    tlmgr update --all --self
    Error in system2("tlmgr", args, ...) : '"tlmgr"' not found
    #第二类
    package ‘TLMGR’ is not available for this version of R
    #等等
    
  4. 在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不适用于此语言环境
停止执行
  1. 点击设置button,选择output options。
    在这里插入图片描述
  2. Output选择为PDF后点击Advanced在这里插入图片描述
  3. 更改LaTeX engine 为xelatex后点击OK
    在这里插入图片描述
    也可以直接在文件头部加入以下代码后输出。
output: 
  pdf_document: 
    latex_engine: xelatex

在这里插入图片描述
来源:https://stackoverflow.com/questions/32794157/package-inputenc-error-unicode-char-u8-in-rstudio
有其他问题欢迎评论探讨~

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐