r - R 中带有 Pandoc Knitr 的带有变音符号的表格

标签 r knitr pandoc

我很难通过 knitr 用变音符号打印我的表格包和 pandoc。相信Name.md文件生成正确,但在 pandoc 处给我错误等级。我做错了什么?没有变音符号,它可以完美运行。

这是我遵循的示例和步骤:

在 R 中复制表

SampleTable <- data.frame(Nazov=c("Kratkodobé záväzky (TA)","Dlhodobé záväzky 
                                 (LA)","Záväzky celkovo (TA)"))

我运行 *.Rmd 文件来创建 Name.md 文件
```{r, echo=FALSE, dpi=600, fig.width=12, fig.height=15, fig.cap="Finančná štruktúra"}
   print(xtable(SampleTable))
```

将 .md 转换为 .pdf
knit("Name.rmd")


system(paste("pandoc -V geometry:margin=1in -o", "Report", ".pdf ", "Name", ".md", 
              sep=""))

编辑:错误:
pandoc.exe: Cannot decode byte '\x20': Data.Text.Encoding.decodeUtf8: Invalid UTF-8
            stream

Warning message:
running command 'pandoc -V geometry:margin=1in -oReport7.pdf ReportNew.md' had status 1

最佳答案

在诸如“geany”之类的文本编辑器中查看文件后,您可以轻松查看文件编码(文件 > 属性),您将看到文件编码为 ISO-8859-1。

但是,如 Pandoc 手册页所述:

Pandoc uses the UTF-8 character encoding for both input and output. If your local character encoding is not UTF-8, you should pipe input and output through iconv:

iconv -t utf-8 input.txt | pandoc | iconv -f utf-8


因此,我在终端上所做的是(假设您已更改到 .md 文件的存储目录):
iconv -f ISO-8859-1 -t UTF-8 md_file.md > new.md
pandoc new.md -o test.pdf

如果您希望从 R 中执行此操作,请像您在现有问题中所做的那样将命令粘贴在一起。

这是我得到的输出:

enter image description here

注意:我应该提到我在 Ubuntu 上并且 iconv 在 Unix 系统中是相当标准的。

关于r - R 中带有 Pandoc Knitr 的带有变音符号的表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18831936/

相关文章:

R 规则,仅我的规则来自特定列

r - Knitr:显示内联代码块的源代码

r - Knitr:Markdown文档中LaTeX环境中的R代码

r - Rmarkdown 中同一行的 Kableextra 表和 ggplot 图(PDF - 不是 Flexdashboard)

windows - 在 Windows 上使用 Pandoc 连接多个 Markdown 文件

r - 使用 'bquote'(或替代方法)从符号构造函数

r - 在 R 中计算互购时间

r - 从热图或基础数据中提取颜色值矩阵

matplotlib - 在R Markdown文档中用Python代码绘制matplotlib图形

r - 当我将 knitr 和 Rscript 与 opts_chunk 一起使用时执行停止