Learn R Programming

functools

functools extends functional programming in R. It accomplishes several goals:

  • Add support to the usual higher order functional suspects (Filter(), Map(), Reduce(), etc.) with higher order functions (Compose(), Memoise(), Partial(), Reject(), Fail_With(), Reduce_Right(), All(), Any(), and Best()).

  • Supply higher order function generators (Andify(), Orify()) to make composing predicate functions easier.

  • Provide wrappers (Apply(), Lapply(), Mapply(), Sapply(), Tapply(), and Vapply()) around their respective base R functionals to create an API with consistent naming convention, positional arguments, and argument names.

  • Implement common constants as functions (True(), False(), Identity(), Null(), Na()) for point-free programming.

  • Extend abstract concepts of existiness and truthiness through functions (Existy(), Truthy()).

functools achieves these goals through three main types of function design patterns:

  • Closures (functions that take data and return functions)

  • Functionals (functions that take functions and return data)

  • Function Operators (functions that take functions and return functions)

Installation

You can install:

  • the latest released version from CRAN with

    install.packages("functools")
  • the latest development version from github with

    if (packageVersion("devtools") < 1.6) {
      install.packages("devtools")
    }
    devtools::install_github("paulhendricks/functools")

If you encounter a clear bug, please file a minimal reproducible example on github.

Copy Link

Version

Install

install.packages('functools')

Monthly Downloads

22

Version

0.2.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

September 2nd, 2015

Functions in functools (0.2.0)

True

True
Compact

Filter NA and NULL values out of a vector, list, or data.frame.
All

Test if all items in an object evaluate to TRUE.
Always

Create a function that that always returns a specific object.
Apply

Wrapper for apply function.
functools

functools: Extending Functional Programming in R
Lapply

Wrapper for lapply function.
Any

Test if any items in an object evaluate to TRUE.
Andify

Predicate function operator that creates new predicate functions linked by the && operator.
Mapply

Wrapper for mapply function.
Compose

Compose multiple functions.
Null

Null
Memoise

Memoise a function.
Existy

Existy
Na

Na
Identity

Identity
Reject

Reject
Fail_With

Fail with a default value.
Orify

Predicate function operator that creates new predicate functions linked by the || operator.
Vapply

Wrapper for vapply function.
Best

Find the best value in a vector.
Tapply

Wrapper for tapply function.
Reduce_Right

Simple wrapper for Reduce, proceeding from the right.
Truthy

Truthy
False

False
Sapply

Wrapper for sapply function.
Partial

Partial apply a function, filling in some arguments.