Suppressing "# A Tibble <R> x <C>" and Column Datatypes

I have this chunk of dplyr code that performs a simple count:

dailyGenerationQA %>% filter(sum_detail_diff > 20) %>% count()

Which generates the following output:

# A tibble: 1 x 1
n
<int>
1 4

Which is fine for me, but when I put this into a R Markdown chunk, I get the same output, when really all I want is just the unadorned count. Is there a chunk option (or Tidyverse thingy) that can suppress the "# A Tibble..." and the column data type? I haven't been able to find anything on my own.

TIA

For this particular case, you can use pull. Use the following:

dailyGenerationQA %>% filter(sum_detail_diff > 20) %>% count() %>% pull(n)
2 Likes

Hi, and welcome! Your question straddles the boundary between abstract enough to not need a reproducible example, called a reprex and those that do. In this case I used the following chunk to replicate your output

```{r code_chunk, echo=FALSE}
library(tidyverse)
n <- enframe(4) %>% select(value) %>% rename(n = value)
n
```

which reproduces your output

A tibble: 1 x 1
      n
  <dbl>
1     4

The expedient approach is to assign the result of your code in the chunk, which leaves nothing for the chunk to output

# [within chunk]
n <- dailyGenerationQA %>% filter(sum_detail_diff > 20) %>% count()

And then do an inline reference to it outside the chunk.

`r n`

which will get you a bare 4.

This will take you only so far in formatting RMarkdown documents, however, and eventually you are going to want to familiarize yourself with chunk options, knitr options, kableExtra, pander and format for greater control over the appearance of output.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.