微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

R summarytools dfSummary无法在RMarkdown选项卡中正确显示

如何解决R summarytools dfSummary无法在RMarkdown选项卡中正确显示

我试图将2 dfSummary输出放入RMarkdown中的选项卡式部分。我想我必须使用 results ='asis'生成图,但是当我使用该选项时,制表符功能会中断。摘要显示在选项卡中,而是在文档中以行形式显示

下面的示例在ToothGrowth数据集上,并显示了我希望解决的问题。

---
title: "test"
output: html_document
---

```{r setup,include = FALSE}
library(summarytools)

st_options(plain.ascii = FALSE               # This is very handy in all Rmd documents,style = "rmarkdown"               # This too,footnote = NA                     # Avoids footnotes which would clutter the results,subtitle.emphasis = FALSE         # This is a setting to experiment with - according to the theme used,it might improve the headings layout
)
           
knitr::opts_chunk$set(results = 'asis')
```

## R Markdown

### {.tabset .tabset-pills}  

#### Numeric Variables  

This section is for numeric variables.  

```{r}
summarytools::dfSummary(ToothGrowth[c('len','dose')],style = "grid",graph.magnif = 0.75,valid.col = FALSE,tmp.img.dir = "/tmp")
```

#### Factor Variables  

This section is for factor variables.  

```{r}
summarytools::dfSummary(ToothGrowth[c('supp')],tmp.img.dir = "/tmp")
```

谢谢!

解决方法

我会尝试这两件事:

  1. 设置headings=FALSE。这样可以防止##与选项卡式内容内部工作方式发生冲突。
  2. 使用# {.tabset .tabset-pills},然后使用## Numeric## Factor。这可能是第一个解决方案的可行替代方案,因为它使用的标题级别与summarytools的标题级别不同。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。