带R包Repmis的重音字母

时间:2019-01-21 05:37:04

标签: r r-markdown citations

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

对此有解决方法吗?

我尝试将options(encoding = "UTF-8")添加到我的.RProfile中,但这无济于事。我的解决方法是将引用复制到另一个围兜文件中,并使用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  

1 个答案:

答案 0 :(得分:0)

通过打开.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]