Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/r-lib/ellipsis
Tools for Working with ...
https://github.com/r-lib/ellipsis
dot-dot-dot ellipsis r
Last synced: 1 day ago
JSON representation
Tools for Working with ...
- Host: GitHub
- URL: https://github.com/r-lib/ellipsis
- Owner: r-lib
- License: other
- Created: 2018-07-06T20:49:16.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2021-10-27T22:49:18.000Z (about 3 years ago)
- Last Synced: 2024-11-23T23:58:43.285Z (18 days ago)
- Topics: dot-dot-dot, ellipsis, r
- Language: R
- Homepage: https://ellipsis.r-lib.org
- Size: 178 KB
- Stars: 141
- Watchers: 8
- Forks: 14
- Open Issues: 7
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - r-lib/ellipsis - Tools for Working with ... (R)
README
---
output: github_document
---```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# ellipsis[![Lifecycle: maturing](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://lifecycle.r-lib.org/articles/stages.html)
[![R-CMD-check](https://github.com/r-lib/ellipsis/workflows/R-CMD-check/badge.svg)](https://github.com/r-lib/ellipsis/actions)
[![CRAN status](https://www.r-pkg.org/badges/version/ellipsis)](https://cran.r-project.org/package=ellipsis)
[![Codecov test coverage](https://codecov.io/gh/r-lib/ellipsis/branch/master/graph/badge.svg)](https://codecov.io/gh/r-lib/ellipsis?branch=master)Adding `...` to a function is a powerful technique because it allows you to accept any number of additional arguments. Unfortunately it comes with a big downside: any misspelled or extraneous arguments will be silently ignored. This package provides tools for making `...` safer:
* `check_dots_evaluated()` errors if any components of `...` are not evaluated.
This allows an S3 generic to state that it expects every input to be
evaluated.* `check_dots_unnamed()` errors if any components of `...` are named. This
allows you to collect arbitrary unnamed arguments, warning if the user
misspells a named argument.* `check_dots_empty()` errors if `...` is used. This allows you to use `...` to
force the user to supply full argument names, while still warning if an
argument name is misspelled.Thanks to [Jenny Bryan](https://github.com/jennybc) for the idea, and [Lionel Henry](https://github.com/lionel-) for the heart of the implementation.
## Installation
Install the released version from CRAN:
```{r, eval = FALSE}
install.packages("ellipsis")
```Or the development version from GitHub:
```{r, eval = FALSE}
devtools::install_github("r-lib/ellipsis")
```## Example
`mean()` is a little dangerous because you might expect it to work like `sum()`:
```{r}
sum(1, 2, 3, 4)
mean(1, 2, 3, 4)
```This silently returns the incorrect result because `mean()` has arguments `x` and `...`. The `...` silently swallows up the additional arguments. We can use `ellipsis::check_dots_used()` to check that every input to `...` is actually used:
```{r, error = TRUE}
safe_mean <- function(x, ..., trim = 0, na.rm = FALSE) {
ellipsis::check_dots_used()
mean(x, ..., trim = trim, na.rm = na.rm)
}safe_mean(1, 2, 3, 4)
```