【问题标题】:Citations in DT:datatableDT 中的引文:数据表
【发布时间】:2020-04-20 16:38:16
【问题描述】:

我正在做一个 bookdown 项目,我们有一个包含引文的大表格。我们以 html 和 pdf 格式输出。 问题是我找不到让引用在表格中呈现的方法。

对于 PDF 输出,此乳胶变通方法有效:https://github.com/haozhu233/kableExtra/issues/214 但是,对于 html 输出,我一直在使用 DT:datatable,但我想不出一种方法来渲染引用。

有没有办法在表格中获取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}
}

【问题讨论】:

    标签: r r-markdown dt bookdown


    【解决方案1】:

    我建议您使用 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()
    ```
    

    或者有链接:

    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 文件时这是否会起作用。我想知道它是否可以跟踪计数。
    • 好吧,因为问题中没有提到,我没有考虑编号引用的问题,我认为将这些引用作为 DT 数据表中的代码并不是什么大问题.确实支持数字引用,但是是的,我怀疑它们需要使用内联代码才能始终如一地运行。我相信 Gitbook 可以选择基本上处理所有章节,就好像它们是一个 Rmd 一样,所以这不应该是一个问题。如需参考,另请参阅“6. 在动态文档中使用RefManageR”arxiv.org/pdf/1403.2036v1.pdf
    猜你喜欢
    • 2018-05-28
    • 1970-01-01
    • 1970-01-01
    • 2016-06-15
    • 1970-01-01
    • 2015-10-02
    • 2016-12-30
    • 2021-05-20
    • 2018-02-01
    相关资源
    最近更新 更多