An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# splice

[![Travis build status](https://travis-ci.org/romainfrancois/splice.svg?branch=master)](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))
```