你一定见过Rmarkdownd的这个错误

找到了一篇中文帖子

  • Rstudio 中的配置:Tools -- Global Options -- General, 设置缺省的编码格式为UTF-8(Default text coding: UTF-8)。当然,如果是默认的[Ask]状态,Rstudio弹框框出来的时候再选 UTF-8 也是可以的。

博客园地址:https://www.cnblogs.com/loca/p/4541679.html

大概的意思就是设置utf-8为默认输出。

我进行修改后却出现来另一个错误

Error: pandoc document conversion failed with error 11

Google后发现一篇有用的帖子

https://github.com/rstudio/rstudio/issues/3661

有更换R收徒弟哦版本的,有更换输出方式的,但是最终唯有这个小脚本最适合并解决问题。运行之后完美解决问题,这里直接放出源代码。这里安装pandoc 2.7.1。

如果有类似的问题,在R中运行下面代码并重启。

# Download pandoc 2.7.1 built with ghc-8.6.4, and instruct
# RStudio + rmarkdown to use it.
path = getwd()
path
local({

# The directory where Pandoc will be extracted. Feel free
# to adjust this path as appropriate.
dir <- path

# The version of Pandoc to be installed.
version <- "2.7.1"

# Create and move to the requested directory.
dir.create(dir, showWarnings = FALSE, recursive = TRUE)
owd <- setwd(dir)
on.exit(setwd(owd), add = TRUE)

# Construct path to pandoc.
root <- "https://s3.amazonaws.com/rstudio-buildtools"
suffix <- sprintf("pandoc-%s-windows-x86_64.zip", version)
url <- file.path(root, "pandoc-rstudio", version, suffix)

# Download and extract pandoc.
file <- basename(url)
utils::download.file(url, destfile = file)
utils::unzip(file)
unlink(file)

# Write .Renviron to update the version of Pandoc used.
entry <- paste("RSTUDIO_PANDOC", shQuote(path.expand(dir)), sep = " = ")
contents <- if (file.exists("~/.Renviron")) readLines("~/.Renviron")
filtered <- grep("^RSTUDIO_PANDOC", contents, value = TRUE, invert = TRUE)
amended <- union(filtered, entry)
writeLines(amended, "~/.Renviron")

# Report change to the user.
writeLines("Updated .Renviron:\n")
writeLines(amended)
writeLines("\nPlease restart RStudio for these changes to take effect.")

})

(0)

相关推荐