After upgrading dplyr
to version 1.0.0 I’m a little bit annoyed by the warnings
(actually you can’t suppress them with warnings = FALSE
)
1
|
`summarise()` regrouping output by 'homeworld' (override with `.groups` argument)
|
But let’s look at an example:
1
2
3
4
5
6
|
library(dplyr, warn.conflicts = FALSE)
iris %>%
group_by(Species) %>%
summarise(
Sepal.Length.mean = mean(Sepal.Length)
)
|
1
|
## `summarise()` ungrouping output (override with `.groups` argument)
|
1
2
3
4
5
6
|
## # A tibble: 3 x 2
## Species Sepal.Length.mean
## <fct> <dbl>
## 1 setosa 5.01
## 2 versicolor 5.94
## 3 virginica 6.59
|
Here you can see the additional informative output which often disturbs my code
when the out put is used in LaTeX-reports etc.
So how to get rid of it?
It’s simple. You can use a dplyr-option
:
1
2
3
4
5
6
7
8
9
10
|
library(dplyr, warn.conflicts = FALSE)
# Suppress summarise info
options(dplyr.summarise.inform = FALSE)
iris %>%
group_by(Species) %>%
summarise(
Sepal.Length.mean = mean(Sepal.Length)
)
|
1
2
3
4
5
6
|
## # A tibble: 3 x 2
## Species Sepal.Length.mean
## <fct> <dbl>
## 1 setosa 5.01
## 2 versicolor 5.94
## 3 virginica 6.59
|
In fact this info text is added to inform about the new .groups
paramater
(see: https://www.tidyverse.org/blog/2020/05/dplyr-1-0-0-last-minute-additions/)
I’m searching for this dplyr-option every other day. So I primarly wrote this
blogpost for me so I haven’t to search for it.
Note for tidyverse
There’s also a magic option for tidyverse
to hide the attaching messages:
So instead of
1
|
## ── Attaching packages ────────────────────────────────────────────────────────────────────────────────────────── tidyverse 1.3.0 ──
|
1
2
3
4
|
## ✓ ggplot2 3.3.2 ✓ purrr 0.3.4
## ✓ tibble 3.0.3 ✓ stringr 1.4.0
## ✓ tidyr 1.1.0 ✓ forcats 0.5.0
## ✓ readr 1.3.1
|
1
2
3
|
## ── Conflicts ───────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
|
you get
1
2
3
4
5
6
7
|
# unload tidyverse and ggplot2 as an example first
detach("package:tidyverse", unload = TRUE)
detach("package:ggplot2", unload = TRUE)
# magic option
options(tidyverse.quiet = TRUE)
library(tidyverse)
|