Coder Social home page Coder Social logo

ellipsis's Introduction

ellipsis

lifecycle

Adding ... to a function specification usually comes with a big downside: any mispelled or extraneous arguments will be silently ignored. This package explores an approach to making ... safer, by inspecting its contents and warning if any elements were not evaluated.

In the long run, this code is likely to live elsewhere (hopefully R-core might be interested so we could make it part of base R). This repository tracks the current state of the experiment.

Thanks to Jenny Bryan for the idea, and Lionel Henry for the heart of the implementation.

Installation

devtools::install_gituhb("hadley/ellipsis")

Example

ellipsis comes with two functions that illustrates how we can make functionals (which pass ... to another argument) and S3 generics (which pass ... on to their methods) safer. safe_map() and safe_median() warn if you supply arguments that are never evaluated.

library(ellipsis)

x <- safe_map(iris[1:4], median, na.mr = TRUE)
#> Warning: Some components of ... were not used: na.mr
x <- safe_map(iris[1:4], median, na.rm = TRUE)
x <- safe_map(iris[1:4], median, 2)
x <- safe_map(iris[1:4], median, 2, 3)
#> Warning: Some components of ... were not used: ..2

x <- safe_median(1:10)
x <- safe_median(1:10, FALSE)
#> Warning: Some components of ... were not used: ..1
x <- safe_median(1:10, na.rm = FALSE)
x <- safe_median(1:10, na.mr = TRUE)
#> Warning: Some components of ... were not used: na.mr

The top-level function handles all evaluation failures so that this only generates a single warning (not one warning from safe_map() and four from safe_median())

x <- safe_map(iris[1:4], safe_median, na.mr = TRUE)
#> Warning: Some components of ... were not used: na.mr

ellipsis's People

Contributors

hadley avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.