Skip to content

mikedecr/prefix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The prefix package for R

prefix provides an ergonomic prefix function interface to built-in infix operators in R.

In short:

  • Expressions like 2 * 3 are called infix expressions. The operator * goes between its arguments.
  • Every infix expression can be written as a prefix expression in R, such as `*`(2, 3). But it isn't very easy to type the backticks, and it isn't easy to read.
  • prefix provides new function bindings for these operators, so your can write your prefix expression as mult(2, 3) instead. Much easier!

prefix provides this functional interface with a more natural feel, similar to the way you might invoke these operations in functional languages like Haskell and Lisp(s).

...but why?

The main idea in prefix is either banal or sublime, depending on your style.

As it is implemented in the code, prefix is nothing but new names for existing functions. If you are happy using infix notation, prefix will seem useless.

But if you are partial to the functional style (pun intended), prefix allows you to interact with primitive operations in R uniformly and consistently with all other functions, allowing smoother and more expressive function composition.

Caveats

This package is in its infancy and subject to aggressive change.

Here's a running list of to-dos:

  • Basic arithmetic
  • Matrix arithmetic
    • outer + kronecker already built in
  • Logical operators
    • xor already built in
    • item_or, item_and naming
  • [-] Indexing / subsetting operations (including set %in%)
    • how to do $?
  • misc:
    • range / iota

Less of a priority:

  • extract-or-replace? (@) (see slot())
  • Control flow keywords?
  • formula
  • assignment

Installation

You can install the development version of prefix (at your own risk) with devtools:

# in the R REPL:
devtools::install_github("mikedecr/prefix")

Examples

library(prefix)

mult(3, 4)  # a * b
# [1] 12

isin(7, c(7, 8, 9))  # a %in% b
# [1] TRUE

or(0, FALSE)  # a | b
# [1] FALSE

About

Prefix functions for R's infix operators

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages