Reputation: 1279
I would like to show, in an rmarkdown document, the printed output of a tibble as shown in the console. i.e.
However, by default, tibbles and other data.frame objects are automatically converted to a tabbed, paginated table showing all contents.
I note that the option to turn off this default behaviour can be set for a whole markdown document by changing the df_print
option to tibble
in the YAML.
However, how do I set the df_print
option to tibble
for just a single R code chunk, so that I can show in an Rmarkdown document what the user will see on the console?
Thanks, Jon
Upvotes: 1
Views: 2380
Reputation: 2797
There's no need to touch the global setting. You can explicitly call the print function tibble:::print.tbl_df(df)
Example:
title: "Untitled"
author: "TC"
date: "7/27/2018"
output:
html_document:
df_print: "kable"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## print tibble
```{r}
df <- tibble::as.tibble(mtcars)
tibble:::print.tbl_df(head(df))
```
## print kable (set in YAML header)
```{r}
head(df)
```
Upvotes: 1