Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R markdown df_print options

Tags:

r

r-markdown

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.

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
```

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

I've tried this:

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

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

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

which also doesn't work.

like image 914
ds440 Avatar asked Nov 30 '16 16:11

ds440


People also ask

How do I create a tab in Rmarkdown?

Syntax in Rmarkdown To implement the tabbed section in an Rmarkdown document like the example above, all you have to do is putting {. tabset} on the right of a header. Then all the content below each sub-header will appear within a tab.

What output formats can be generate from R markdown?

There are two types of output formats in the rmarkdown package: documents, and presentations.

How do I change a document in Rmarkdown?

To transform your markdown file into an HTML, PDF, or Word document, click the “Knit” icon that appears above your file in the scripts editor. A drop down menu will let you select the type of output that you want. When you click the button, rmarkdown will duplicate your text in the new file format.


1 Answers

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.

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
```
like image 175
ds440 Avatar answered Oct 14 '22 07:10

ds440