gpt4 book ai didi

r - DT :datatable 中的引用

转载 作者:行者123 更新时间:2023-12-02 07:51:33 24 4
gpt4 key购买 nike

我正在开展一个 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}
}

最佳答案

我建议您使用 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 - DT :datatable 中的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59556135/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com