我试图在我的R Markdown Word报告中交叉引用使用qwraps2::summary_table()
创建的汇总表,但它不适用于我下面的.Rmd文件。
---
title: "Summary table in R Markdown"
output: bookdown::word_document2
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
A summary of the group is in Table @ref(tab:summ-tab):
library(tidyverse)
library(qwraps2)
options(qwraps2_markup = "markdown")
tdf <- tibble(
age = runif(n = 30, min = 20, max = 40),
sex = sample(c("M", "F"), size = 30, replace = TRUE),
bmi = runif(n = 30, min = 15, max = 45),
disease = sample(1:2, size = 30, replace = TRUE)
)
summary_str <- list(
"Sex, n (%)" = list(
"Male" = ~ n_perc0(sex == "M", digits = 1),
"Female" = ~ n_perc0(sex == "F", digits = 1)
),
"Age, mean ± SD" = list(
"Age (yr)" = ~ mean_sd(age, digits = 0)
),
"BMI, mean ± SD" = list(
"BMI (kg m^-2^)" = ~ mean_sd(bmi, digits = 1)
)
)
tdf %>%
group_by(disease) %>%
summary_table(summary_str) %>%
print()
# knitr::kable(caption = "Personal summary")
# qable(caption = "Personal summary")
字符串
使用`print()`作为`qwraps2_summary_table`对象的输出方法的.docx文件的屏幕截图:
![](https://i.stack.imgur.com/t9c3R.png)
对于我使用`knitr::kable()`创建的其他表,`knitr::kable()`将生成一个表标签用于交叉引用,所以我尝试使用`knitr::kable()`而不是`print()`方法输出表。交叉引用工作,但表本身在我的.docx文件中没有正确呈现:
![](https://i.stack.imgur.com/5iozl.png)
考虑到`qwraps2::qable()`是`knitr::kable()`的 Package 器,我也尝试了它,但是交叉引用再次被破坏,它只呈现了表的一半(缺少组标题):
![](https://i.stack.imgur.com/d7XWu.png)
我在网上搜索,但似乎没有找到解决我的问题,所以真的很感激有人的帮助。
1条答案
按热度按时间ercv8c1e1#
qwraps2的0.6.0版本修复了这个问题。在
summary_table
调用中添加参数qable_args
和kable_args
将允许从一个调用到下一个调用正确传递参数,即从summary_table
到qable
,然后到knitr::kable
。下面是一个.Rmd文件示例和生成的.docx文件的屏幕截图,这些文件是通过在.Rmd文件上调用
rmarkdown::render
创建的:A summary of the the data by disease group is in Table @ref(tab:stab) and is
generated via
qwraps2::summary_table
.More text goes here ... Table @ref(tab:stab2) uses
knitr::kable
directly.More text goes here.
More text goes here.