R markdown df_print 选项 [英] R markdown df_print options

查看:75
本文介绍了R markdown df_print 选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 RStudio 中有一个 R markdown 文档,其中打印了一个 data.table.我想设置数据框打印选项来控制打印的行数和列数,如here.

I have a R markdown document in RStudio, where a data.table is printed. I want to set the data frame print options to control printed number of rows and columns, as described here.

这是一个最小的示例 .Rmd 文件:

Here is a minimal example .Rmd file:

---
output: 
  html_document: 
    fig_height: 8
    fig_width: 10
    df_print: paged
---

```{r}
knitr::opts_chunk$set(echo = FALSE)
cars
```

在哪里/如何设置 rows.print 选项?

Where/how do I set the rows.print option?

我已经试过了:

---
output: 
  html_document: 
    fig_height: 8
    fig_width: 10
    df_print: paged
    rows.print: 25
---

这不起作用(仍然是默认的 10 行),还有这个:

which doesn't work (still at default 10 rows), and this:

```{r}
knitr::opts_chunk$set(echo = FALSE, rows.print=25)
cars
```

这也不起作用.

推荐答案

knitr::opts_chunk$set(rows.print=25) 选项设置仅适用于后续块,因此在最小例如它不会改变设置.

The knitr::opts_chunk$set(rows.print=25) option setting applies only to subsequent chunks, hence in the minimal example it doesn't change the setting.

该选项可以在chunk1所示的chunk中设置,也可以在opts_chunk中全局设置以用于后续chunk.

The option can be set in the chunk as shown in chunk1 or globally in opts_chunk for subsequent chunks.

```{r chunk1, rows.print=15}
knitr::opts_chunk$set(echo = TRUE, rows.print=25)
cars #15 rows printed
```

```{r chunk2}
cars #25 rows printed
```

这篇关于R markdown df_print 选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆