【问题标题】:Accented letters with R package Repmis带有 R 包 Repmis 的重音字母
【发布时间】:2019-01-21 05:37:03
【问题描述】:

我使用repmis 来处理我的报告中的引用,但是当引用包含重音字符时它不会编译 - 在这种情况下引用nlme 包时。

有解决办法吗?

我尝试将 options(encoding = "UTF-8") 添加到我的 .RProfile 中,但这没有帮助。我的解决方法是将引用复制到另一个 bib 文件中,并使用 Window 字符映射中的符号。虽然这可行,但这不是我正在寻找的解决方法。

谢谢。

错误信息:

pandoc-citeproc:无法解码字节“\xe9”: Data.Text.Internal.Encoding.decodeUtf8:无效的 UTF-8 流错误 运行过滤器 pandoc-citeproc:过滤器返回错误状态 1 错误: pandoc 文档转换失败,错误 83 执行停止

示例 .Rmd:

---
title: "Untitled"
author: "Paul Stevenson"
date: "21 January 2019"
output: html_document
bibliography:
  - packages.bib
---

```{r}
library(repmis)
LoadandCite(pkgs = c("nlme"),
            file = "packages.bib")

```

Reference [@R-nlme]

围兜条目:

@Manual{R-nlme,
  title = {nlme: Linear and Nonlinear Mixed Effects Models},
  author = {José Pinheiro and Douglas Bates and {R-core}},
  year = {2018},
  note = {R package version 3.1-137},
  url = {https://CRAN.R-project.org/package=nlme},
}

sessionInfo():

R version 3.5.2 (2018-12-20)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252   
[3] LC_MONETARY=English_Australia.1252 LC_NUMERIC=C                      
[5] LC_TIME=English_Australia.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] compiler_3.5.2  htmltools_0.3.6 tools_3.5.2     yaml_2.2.0     
 [5] Rcpp_1.0.0      rmarkdown_1.11  knitr_1.21      xfun_0.4       
 [9] digest_0.6.18   evaluate_0.12  

【问题讨论】:

  • \xe9 不是 UTF-8 字符。它看起来像“é”的 Latin1。从错误消息中,Pandoc 期待 UTF-8。因此,我建议阅读您的 .bib 文件,确保它在您的编辑器中看起来不错,然后将其显式保存为 UTF-8。
  • 谢谢,围兜文件有一个问号,我可以通过复制一个 UTF-8 字符来解决这个问题。问题是 repmis 试图自动化从说明中的信息引用包的过程,理想情况下会有一个修复程序允许它工作/重新编码它得到的任何东西。
  • 如果您使用的是 Windows,repmis 可能会使用 Latin1 编码。 iconv 程序可以更改文件编码;我忘记了它是否包含在 Rtools 集合中,但如果没有的话应该可以使用。

标签: r r-markdown citations


【解决方案1】:

通过打开.bib 并使用write.table(fileEncoding = "UTF-8") 保存找到了更顺畅的解决方法。请参阅下面的recoder 函数:

---
title: "Untitled"
author: "Paul Stevenson"
date: "21 January 2019"
output: html_document
bibliography:
  - packages.bib
---

```{r}
recoder <- function(x) {
  dat <- read.delim(file = x, header = F, stringsAsFactors = F, quote = "")
  write.table(dat, file = x, row.names = F, quote = F, col.names = F, fileEncoding = "UTF-8")
}

library(repmis)
library(nlme)
LoadandCite(pkgs = c("nlme", "biometrics"), file = "packages.bib")
recoder("packages.bib")

```

Reference [@R-nlme]

【讨论】:

    猜你喜欢
    • 2017-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-21
    相关资源
    最近更新 更多