如何print.summarytools-使用我们的无view()包装器

时间:2019-04-05 23:12:28

标签: r visual-studio-2017 summarytools

我正在尝试创建一个表(用于包含在MSFT Word表中),就像在这里找到的那​​样:

https://github.com/dcomtois/summarytools

3-descr():描述性单变量统计

但是

descr(iris, style = "rmarkdown")
style = "rmarkdown" is actually set as an st_options() - see below

如文本中所示,不会创建文档后的表格。

view(descr(iris, style = "rmarkdown"))

创建文档后的表格-如下。

view(descr(iris), "browser")
print(descr(iris), "browser")

view(descr(iris), "viewer")
print(descr(iris), "viewer")

以下内容以“使用带有编织器的皮德”形式创建表(请参见:http://rapporter.github.io/pander/knitr.html

view(descr(iris), "pander")
print(descr(iris), "pander")

据我所知(此时),我需要学习编织器(https://yihui.name/knitr/)-对其进行研究。

冒着过于冗长的风险,这是我的“环境”:

R version 3.5.1 (2018-07-02) -- "Feather Spray"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

library(summarytools)
library(dplyr)
library(data.table)
library(pander)
library(knitr)
library(rmarkdown)

<<<<<<源于开始

st_options(bootstrap.css = FALSE, # Already part of the theme so no need for it
           plain.ascii = FALSE, # One of the essential settings
           style = "rmarkdown", # Idem.
           dfSummary.silent = TRUE, # Suppresses messages about temporary files
           footnote = NA, # Keeping the results minimalistic
           subtitle.emphasis = FALSE) # For the vignette theme, this gives much better results.

st_css()

library(knitr)
opts_chunk$set(comment = NA, prompt = FALSE, cache = FALSE, echo = TRUE, results = 'asis')

library(tables)

2 个答案:

答案 0 :(得分:0)

view()打开的选项卡实际上并不是要打印或选择的。您是指实际打印在纸上吗? R并不是真的。尝试将数据导出到csv文件或其他内容。

 write.csv(MyData, "My data file.csv")

答案 1 :(得分:0)

要使用 knitr rmarkdown 打印 summarytools 对象,您有两个选择:

  1. 通过设置style = "rmarkdown"plain.ascii = FALSE来使用降价样式的输出,使用st_options()可以正确设置。编织程序块选项results需要设置为“ asis”:

    ```{r, results='asis'}
    descr(iris, style = "rmarkdown", plain.ascii = FALSE)
    ```
    

    由于已全局设置了style和plain.ascii选项,因此可以在函数调用中省略这些选项。


  1. 您还可以使用HTML渲染,使摘要工具可以在后台使用htmltools来生成html代码。

    ```{r, results='asis'}
    print(descr(iris), method = "render")
    ```
    

将css包含在文档顶部的块中并使用以下块选项也是一个好主意:

```{r, results='asis', echo=FALSE}
st_css()
```

有关更多信息和示例,请参见this vignette