0
votes

I would like to show, in an rmarkdown document, the printed output of a tibble as shown in the console. i.e.

  • First line: dimension summary;
  • then the column headers;
  • then classes of variables;
  • then first 10 lines of the tibble;
  • then number of rows not shown.

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

1

1 Answers

1
votes

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

output html