Skip to content

Latest commit

 

History

History
80 lines (56 loc) · 1.52 KB

README.md

File metadata and controls

80 lines (56 loc) · 1.52 KB

PIDO.R package

Overview

🛠Utils package. Contains:

  • Functional analogues of dplyr's pipe operator %>%, such as %map% etc. Supports default R types, for example dataframe
  • Own syntax of λambda functions for this pipe operators (and pipe operators also support default R functions function(...) {...})
  • Porter stemmer for 🇬🇧 english and 🇷🇺 Russian languages
  • Text tokenizers by sentences, words, n-gramms

Install

library(devtools)

install_github('d0rj/pido')

library(pido)

Examples

Lambda functions

Syntax variation

1:4 %map% (num ~ num^2) # first variant
1:4 %map% (~ num^2) # another variant
1:4 %map% (~ .^2) # third

is equivalent of

1:4 %>% map(~ x^2) # in dplyr

sapply(1:4, function(x) x^2) # or without packages

Multiple arguments

list(c(1, 2), c(2, 3)) %map% (first ~ second ~ first * second) # first
list(c(1, 2), c(2, 3)) %map% (~ x * y) # and second variant

is equivalent of

sapply(list(c(1, 2), c(2, 3)), function(x, y) x * y)

Multi-line lambda

list(c(1, 2), c(2, 3)) %map% (~ {
    dbl <- x * 2
    trpl <- y * 3
    return (dbl + trpl)
})

this code will work correctly and will be equivalent of

sapply(list(c(1, 2), c(2, 3)), function(x, y) {
    dbl <- x * 2
    trpl <- y * 3
    return (dbl + trpl)
})

Notes

  • Distribution-ready
  • More tests will be added
  • CRAN package

PIDO abbreviation stands for it.