无法在 kable 表中呈现引文

Jes*_*ett 3 markdown r r-markdown bookdown

我无法使用默认的 pdf_document、bookdown::pdf_document2 或 html_document 来呈现 kable 表内的引文。如下所示,在引文周围强制使用引号 (") 不会

\n\n

(注意:“nocite”作为控件存在,.bib 中没有任何内容)。\n文件“bib.bib”位于同一目录中,内容如下:

\n\n
@article{roy2019growth,\n  title={Growth pattern and oxygen isotopic systematics of modern freshwater mollusks along an elevation transect: Implications for paleoclimate reconstruction},\n  author={Roy, Rupsa and Wang, Yang and Jiang, Shijun},\n  journal={Palaeogeography, Palaeoclimatology, Palaeoecology},\n  pages={109243},\n  year={2019},\n  publisher={Elsevier}\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

代表代码

\n\n
---\n output:\n    bookdown::pdf_document2\n# output: pdf_document\nbibliography: bib.bib\n---\n\nCitation works, see [@roy2019growth]?\n\n\n```{r results="asis"}\n# using "asis" results\na <- c(1,2)\nb <- c("@roy2019growth", "@nocite")\ndf <- data.frame(a,b)\nkableExtra::kable(df)\n```\n\n\n```{r}\n# without as is results\nkableExtra::kable(df)\n```\n\n```{r}\n# Try explicit \'"\' quotes\ndf <- data.frame(a,b = paste0(\'"\',b,\'"\'))\nkableExtra::kable(df)\n```\n\n# My Reference\n
Run Code Online (Sandbox Code Playgroud)\n\n

会议信息

\n\n

R 版本 3.5.3 (2019-03-11)\n平台:i386-w64-mingw32/i386(32 位)\n运行环境:Windows 7 x64(内部版本 7601)Service Pack 1

\n\n

矩阵产品:默认

\n\n

区域设置:\n[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252\n[4] LC_NUMERIC=C LC_TIME=English_United States.1252

\n\n

附加基础包:\n[1] 统计图形 grDevices utils 数据集 方法基础

\n\n

其他附加包:\n[1] kableExtra_1.0.1

\n\n

通过命名空间加载(且未附加):\n [1] Rcpp_1.0.1 rstudioapi_0.10 knitr_1.23 xml2_1.2.0 magrittr_1.5 hms_0.4.2
\n [7] rvest_0.3.4 munsell_0.5.0 viridisLite_0.3.0 colorspace_1.4 -1 R6_2.4.0 rlang_0.4.0
\n[13] highr_0.8 stringr_1.4.0 httr_1.4.0 tools_3.5.3 webshot_0.5.1 xfun_0.8
\n[19] htmltools_0.3.6 yaml_2.2.0摘要_0.6.20 tibble_2.1.3 bookdown_0。 9 crayon_1.3.4
\n[25] readr_1.3.1glue_1.3.1evaluate_0.14 rmarkdown_1.14 stringi_1.4.3compiler_3.5.3
\n[31]pillar_1.4.2scales_1.0.0pkgconfig_2.0.2

\n\n

从 .rmd 渲染 .md 会产生所需的输出

\n\n
Citation works, see (Roy, Wang, and Jiang 2019)?\n\n    # using "asis" results\n    a <- c(1,2)\n    b <- c("@roy2019growth", "@nocite")\n    df <- data.frame(a,b)\n    kableExtra::kable(df)\n\n<table>\n<thead>\n<tr>\n<th style="text-align:right;">\na\n</th>\n<th style="text-align:left;">\nb\n</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td style="text-align:right;">\n1\n</td>\n<td style="text-align:left;">\nRoy, Wang, and Jiang (2019)\n</td>\n</tr>\n<tr>\n<td style="text-align:right;">\n2\n</td>\n<td style="text-align:left;">\n(<span class="citeproc-not-found"\ndata-reference-id="nocite">**???**</span>)\n</td>\n</tr>\n</tbody>\n</table>\n\n    # without as is results\n    kableExtra::kable(df)\n\n<table>\n<thead>\n<tr>\n<th style="text-align:right;">\na\n</th>\n<th style="text-align:left;">\nb\n</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td style="text-align:right;">\n1\n</td>\n<td style="text-align:left;">\nRoy, Wang, and Jiang (2019)\n</td>\n</tr>\n<tr>\n<td style="text-align:right;">\n2\n</td>\n<td style="text-align:left;">\n(<span class="citeproc-not-found"\ndata-reference-id="nocite">**???**</span>)\n</td>\n</tr>\n</tbody>\n</table>\n\n    # Try explicit \'"\' quotes\n    df <- data.frame(a,b = paste0(\'"\',b,\'"\'))\n    kableExtra::kable(df)\n\n<table>\n<thead>\n<tr>\n<th style="text-align:right;">\na\n</th>\n<th style="text-align:left;">\nb\n</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td style="text-align:right;">\n1\n</td>\n<td style="text-align:left;">\n"(<span class="citeproc-not-found"\ndata-reference-id="roy2019growth&amp;quot">**???**</span>);\n</td>\n</tr>\n<tr>\n<td style="text-align:right;">\n2\n</td>\n<td style="text-align:left;">\n"(<span class="citeproc-not-found"\ndata-reference-id="nocite&amp;quot">**???**</span>);\n</td>\n</tr>\n</tbody>\n</table>\n\nMy Reference\n============\n\nRoy, Rupsa, Yang Wang, and Shijun Jiang. 2019. \xe2\x80\x9cGrowth Pattern and\nOxygen Isotopic Systematics of Modern Freshwater Mollusks Along an\nElevation Transect: Implications for Paleoclimate Reconstruction.\xe2\x80\x9d\n*Palaeogeography, Palaeoclimatology, Palaeoecology*, 109243.\n
Run Code Online (Sandbox Code Playgroud)\n

Jes*_*ett 6

@hao-ye找到了一个很好的解决方案,在 kable() 中指定“markdown”格式:enter code here

kableExtra::kable(dat,
      format = "markdown")
Run Code Online (Sandbox Code Playgroud)