在 DT:datatable 中的引用

6
我正在进行一个bookdown项目,其中包含大量的表格和引用。我们同时输出html和pdf文件。
问题在于我找不到一种让引用在表格中渲染的方法。
对于PDF输出,可以使用latex解决此问题,详见:https://github.com/haozhu233/kableExtra/issues/214 然而,对于HTML输出,我一直在使用DT:datatable,但我无法找到一种方法使得引用能够正常渲染。
是否有一种方法可以在表格中获取markdown处理后的引用呢?
下面是一个markdown示例:
---
title: "Untitled"
output: html_document
bibliography: ["references.bib"]
---


In text citation [@chambers_2012].


A plan data.frame can render the reference if inserted as text that markdown can parse.

```{r, results='asis'}
library(dplyr)
library(DT)

data_frame(citation = "[@chambers_2012]")

```

But not in a DT.

```{r, results='asis'}
library(dplyr)
library(DT)

data_frame(citation = "[@chambers_2012]") %>% datatable()

```



# bibliography

样例参考文献.bib

@article{chambers_2012,
title = {A cross-platform toolkit for mass spectrometry and proteomics.},
author = {Chambers, Matthew C and Maclean, Brendan and Burke, Robert and Amodei, Dario and Ruderman, Daniel L and Neumann, Steffen and Gatto, Laurent and Fischer, Bernd and Pratt, Brian and Egertson, Jarrett and Hoff, Katherine and Kessner, Darren and Tasman, Natalie and Shulman, Nicholas and Frewen, Barbara and Baker, Tahmina A and Brusniak, Mi-Youn and Paulse, Christopher and Creasy, David and Flashner, Lisa and Kani, Kian and Moulding, Chris and Seymour, Sean L and Nuwaysir, Lydia M and Lefebvre, Brent and Kuhlmann, Frank and Roark, Joe and Rainer, Paape and Detlev, Suckau and Hemenway, Tina and Huhmer, Andreas and Langridge, James and Connolly, Brian and Chadick, Trey and Holly, Krisztina and Eckels, Josh and Deutsch, Eric W and Moritz, Robert L and Katz, Jonathan E and Agus, David B and {MacCoss}, Michael and Tabb, David L and Mallick, Parag},
pages = {918-920},
url = {http://www.nature.com/doifinder/10.1038/nbt.2377},
year = {2012},
month = {oct},
urldate = {2018-01-13},
journal = {Nature Biotechnology},
volume = {30},
number = {10},
issn = {1087-0156},
doi = {10.1038/nbt.2377},
pmid = {23051804},
pmcid = {PMC3471674},
f1000-projects = {shared citations}
}
1个回答

4

我建议您使用 RefManageR 软件包对引用进行渲染。

```{r}
library("RefManageR")
bib <- ReadBib(file = "references.bib")

invisible(data_frame(citation = RefManageR::TextCite(bib = bib)))
```


```{r}
data_frame(citation = RefManageR::TextCite(bib = bib,
                                           "chambers_2012",
                                           .opts = list(max.names = 1))) %>%
  DT::datatable()
```

datatable example screenshot

或者使用链接:

data_frame(citation = RefManageR::TextCite(bib = bib,
                                           "chambers_2012",
                                           .opts = list(style = "html",
                                                        max.names = 1))) %>%
  DT::datatable(escape = FALSE)

请查看?BibOptions,以获取更多有关输出格式、链接类型等方面的选项。

顺便提一下,由于某些原因,第一次调用函数似乎没有完全考虑到所有给定的选项,因此需要使用invisible()函数。


有趣。谢谢!我猜这需要我们在所有的文本引用中也使用 R 代码(实际上我们使用数字引用)?那会很尴尬。我还想知道(因为我还没有尝试过),如果我们在 gitbook 中有单独的 Rmd 文件,这是否有效?我想知道它是否能跟踪编号。 - Jan Stanstrup
好的,由于问题中没有提到编号引用的问题,我没有考虑到这个问题,并且我认为将这些引用作为DT数据表中的代码不会是一个大问题。数字引用确实得到了支持,但是我怀疑它们需要使用内联代码才能保持一致性。我相信Gitbook有选项可以将所有章节处理为单个Rmd,因此这不应该是一个问题。有关参考,请参阅“6.在动态文档中使用RefManageR”一节 https://arxiv.org/pdf/1403.2036v1.pdf - giocomai

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接