Giter VIP home page Giter VIP logo

enumr's Introduction

enumr

Lifecycle: experimental codecov R-CMD-check

Overview

{enumr} implements static enumerations in R. At their most basic, enums are lists that have unique name/value pairs (called 'members'), and are 'static' in that they cannot be modified after their definition.

Why use enums? Some examples:

  • Improve code self-documentation by explicitly defining name/value pairs
  • Reduce the occurrence of code-breaking typos
  • Prevent accidental overwriting of variables
  • Easily change values in the future

Installation

Release build

install.packages('enumr', repos = 'https://elianhugh.r-universe.dev')

Development build

pak::pkg_install('ElianHugh/enumr@main')
# or
devtools::install_github('ElianHugh/enumr@main')

Usage

Enumr implements two classes of enum: numeric and generic. Both are created with the enum() function, {enumr} handles the identification. You don't need to worry about how they work in implementation, just know that there are rules for what constitutes a numeric vs. generic enum.

Numeric enums only permit numeric values in their name/value pairs. Numeric values include formulas/equations that evaluate to a numeric value. Numeric enum members do not need to have values explicitly defined. Instead, each member's value is either the index of the member, or the value of the previous member plus 1 - this is called 'implicit definition'.

enum(
    cat,
    dog,
    bird
)

#> # A numeric enum: 3 members
#>  int cat : 1
#>  int dog : 2
#>  int bird : 3

Generic enum members can be of any type, even including enums themselves. Each name/value pair must be explicitly defined, and each value must evaluate to a value.

enum(
    a = mtcars,
    b = PlantGrowth,
    c = airquality
)

#> # A generic enum: 3 members
#>  df a : <32 × 11>
#>  df b : <30 × 2>
#>  df c : <153 × 6>

See the pkgdown site for more information on enums, and other features of the {enumr} package, such as coercion, NSE, and typed integration.

Inspiration

Code of Conduct

Please note that the enumr project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

enumr's People

Contributors

elianhugh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 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.