https://github.com/romainfrancois/splice
splice helpers for dplyr
https://github.com/romainfrancois/splice
Last synced: 1 day ago
JSON representation
splice helpers for dplyr
- Host: GitHub
- URL: https://github.com/romainfrancois/splice
- Owner: romainfrancois
- License: other
- Created: 2019-01-30T12:41:04.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-06-28T13:42:40.000Z (almost 2 years ago)
- Last Synced: 2025-04-13T00:42:17.479Z (1 day ago)
- Language: R
- Size: 6.84 KB
- Stars: 10
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - romainfrancois/splice - splice helpers for dplyr (R)
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# splice[](https://travis-ci.org/romainfrancois/splice)
`splice` is an experimental package that brings some capabilities of
`dplyr::summarise_(all,if,at)` to `dplyr::summarise()` directly.## Installation
You can install from github:
``` r
# install.packages("remotes")
devtools::install_github("romainfrancois/splice")
```## Example
The motivating example was "how do I get the mean of all variables AND the number of observations".
There are many ways to get just that information, but I wanted to use `dplyr::summarise_all()`
which would get me the means, but not the number of observations.`summarise(!!!all_(...))` is the same as `summarise_all(...)` but having `!!!all_()` inside
`summarise()` lets you add other things as well:```{r example}
library(dplyr, warn.conflicts = FALSE)
library(splice)iris %>%
group_by(Species) %>%
summarise(n = n(), !!!all_(mean))
```Similarly, `if_()` and `at_()`:
```{r}
iris %>%
summarise(n = n(), !!!if_(is.numeric, mean))iris %>%
summarise(n = n(), !!!at_(vars(starts_with("Sepal")), mean))
```