Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/s-fleck/lest
Vectorised Nested if-else Statements Similar to SQL CASE WHEN (forked from dplyr)
https://github.com/s-fleck/lest
dplyr ifelse r recoding
Last synced: about 2 months ago
JSON representation
Vectorised Nested if-else Statements Similar to SQL CASE WHEN (forked from dplyr)
- Host: GitHub
- URL: https://github.com/s-fleck/lest
- Owner: s-fleck
- License: other
- Created: 2018-08-06T05:26:32.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-02-09T08:47:38.000Z (12 months ago)
- Last Synced: 2024-12-01T12:47:17.465Z (about 2 months ago)
- Topics: dplyr, ifelse, r, recoding
- Language: R
- Homepage: https://s-fleck.github.io/lest/
- Size: 69.3 KB
- Stars: 24
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
**This package is obsolete as dplyr has saner dependencies now, and data.table also implemented a similar function**
# lest
[![CRAN status](https://www.r-pkg.org/badges/version/lest)](https://cran.r-project.org/package=lest)
[![lifecycle](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://www.tidyverse.org/lifecycle/#stable)
[![Travis build status](https://travis-ci.org/s-fleck/lest.svg?branch=master)](https://travis-ci.org/s-fleck/lest)Lest provides two functions for vectorised conditional recoding of variables.
`case_when()` enables you to vectorise multiple `if` and `else` statements (like
`CASE WHEN` in SQL). `if_else()` is a stricter and more predictable version of
`base::ifelse()` that preserves attributes (and therefore works with Dates). The
functions in lest are forks of the
[dplyr](https://CRAN.R-project.org/package=dplyr) functions of
the same name. For more infos please refer to the [documentation](https://s-fleck.github.io/lest/).Why use lest?
----------------------------------Use this package if you like the semantics of `dplyr::case_when()`, but do not
want to use dplyr because of the dependencies it comes with.
**If you already use dplyr in your project, you gain no advantage from lest**.
`lest::case_when()` and `lest::if_else()` behave exactly identical to
the dplyr equivalents, just that they do not support tidyeval syntax
(like `!!!`).Dependencies
----------------------------------**lest** depends only on base R, and will never add any external dependencies.
Installation
------------You can install lest from GitHub with:
``` r
# install.packages("devtools")
devtools::install_github("s-fleck/lest")
```Example
-------``` r
x <- 1:50case_when(
x %% 35 == 0 ~ "fizz buzz",
x %% 5 == 0 ~ "fizz",
x %% 7 == 0 ~ "buzz",
TRUE ~ as.character(x)
)case_when(
x %% 35 == 0 ~ 35,
x %% 5 == 0 ~ 5,
x %% 7 == 0 ~ 7,
TRUE ~ NA
)```