Coder Social home page Coder Social logo

batman's Introduction

NA N-A N/A Batman

batman is a package for taking representations of logical values commonly found in qualitative and categorical data, and mapping them to actual logical values.

In survey data and similar it's not uncommon to see logical values represented as things like:

  1. "Yes"
  2. "No"
  3. "N/A"

This is nice and all, but when you throw it into R...

> as.logical(c("Yes","No","N/A"))
[1] NA NA NA

batman maps common representations to actual logicals. It contains one core function, to_logical, designed to do just that:

> library(batman)
> to_logical(c("Yes","No", "N/A"))
[1]  TRUE FALSE    NA

The goal is to have it not only provide this functionality, but provide this functionality in an internationalised way - with support for as many languages as possible. If you're interested in contributing localised equivalents to TRUE or FALSE values, please open a GitHub isuse with your translations! You'll be credited in the DESCRIPTION file. See the contribution guidelines.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Installation

batman is on CRAN: installation consists of:

install.packages("batman")

Dependencies

Other than base R, the only dependency is Rcpp, which we use for added speed when parsing strings (and it's worthwhile - the code can handle 700k strings in 137 milliseconds)

batman's People

Contributors

ironholds avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

leeper tjebo

batman's Issues

Just use match()

This is much faster. Good GOD did I overengineer this package.

Feature request - warning instead of error when applying to_logical to other than character vector

Not sure if this nice little package is still maintained. This is a feature request.

Currently, to_logical does not accept anything else than character vectors. That's really limiting.
A very frequent use case would be to be able to pass this function in for example dplyr::mutate on a set of columns selected with tidy select, even if this should sometimes capture other columns than characters - instead of resulting in an error, it would be good if just the same vector would be returned and maybe a warning instead.

library(batman)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
foo0 <- foo1 <- data.frame(cat1 = c("Y", "N"))
foo1 <- data.frame(cat1 = c("Y", "N"), cat2 = c(T, F))
foo2 <- data.frame(cat1 = c("Y", "N"), cat2 = c(T, F), cat3 = 0:1)

mutate(foo0,across(everything(), to_logical))
#>    cat1
#> 1  TRUE
#> 2 FALSE
mutate(foo1,across(everything(), to_logical))
#> Error: Problem with `mutate()` input `..1`.
#> x Expecting a string vector: [type=logical; required=STRSXP].
#> ℹ Input `..1` is `(function (.cols = everything(), .fns = NULL, ..., .names = NULL) ...`.
mutate(foo2,across(everything(), to_logical))
#> Error: Problem with `mutate()` input `..1`.
#> x Expecting a string vector: [type=logical; required=STRSXP].
#> ℹ Input `..1` is `(function (.cols = everything(), .fns = NULL, ..., .names = NULL) ...`.

Created on 2021-03-21 by the reprex package (v1.0.0)

extending to other interchangeable things

Dear Oliver,

Based on your suggestion, I am adding the following as a potential suggestion for generalizing batman:

The other common interchangeable things you see on surveys are integers written in english: 1 as "one", 2 as "two" etc.

I believe we can exploit venables english package to easily support english lang.

Multilingual support?

Great idea! How about multilingual support, either as a function argument or in response to the language environment?

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.