我试图交叉引用qwraps2::summary_table()
在我的 R Markdown Word 报告中创建的汇总表,但它不适用于下面的 .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):
```{r summ-tab, results="asis"}
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()
使用作为对象的输出方法的 .docx 文件的屏幕截图qwraps2_summary_table
:
对于使用创建的其他表knitr::kable()
,knitr::kable()
会生成一个表标签以进行交叉引用,因此我尝试使用knitr::kable()
而不是print()
方法输出表。交叉引用有效,但表格本身未在我的 .docx 文件中正确呈现:
考虑到它qwraps2::qable()
是 的包装器knitr::kable()
,我也尝试过,但交叉引用再次被破坏,它只渲染了一半的表格(缺少组标题):
我在网上搜索但似乎没有找到解决我的问题的方法,所以非常感谢有人的帮助。