LoginSignup
8
8

More than 5 years have passed since last update.

R: free operator language. (自由演算子言語R)

Posted at

In R, you can freely define a new binary operator with the form of %hoge% where hoge is arbitral literal. This philosophy allows us to flexibly extend the original syntax; actually free operators are sometimes very useful in terms of readability/writability.

At the same time, however, this means R has a lot of duplicated operators as shown below. If you load two or more packages that export free operators, you may suffer from name conflicts and it will be hard to predict the behavior.

(Rって好きに演算子作れて、それはそれでいいんだけど、パッケージ間の名前衝突多すぎて危ないんじゃね?)

Data from http://finzi.psych.upenn.edu/R/library/ on Oct, 25, 2014.

We show only the packages on CRAN, but recent packages on github may tend more to use free operator.

(CRANのパッケージだけ載せてるけど、githubの奴も入れるともっと多いかも)

Duplicated free operators (重複のある自由演算子)

Ind Op Package Description
1 %nin% BBmisc Simply a negated 'in' operator.
1 %nin% DescTools Find Matching (or Non-Matching) Elements
1 %nin% Hmisc Find Matching (or Non-Matching) Elements
1 %nin% memisc Negative Match
2 %*% bigalgebra %*%,big.matrix,big.matrix-method
2 %*% compositions inner product for matrices and vectors
2 %*% compositions inner product for datasets with a vector space structure
2 %*% compositions inner product for datasets with vector scale
2 %*% gmatrix Matrix Multiplication
2 %*% HiPLARM Matrix Multiplication of two matrices using GPU or multi-core
2 %*% kinship Basic Linear Algebra for classes bdsmatrix and
2 %*% Matrix Matrix (Cross) Products (of Transpose)
2 %*% orientlib %*%,orientation,orientation-method
2 %*% quaternions Linear Algebra with quaternions
3 %>% dendextend Pipe an object forward into a function call/expression.
3 %>% ggvis Pipe graphics
3 %>% gmailr Pipe statements
3 %>% magrittr Pipe an object forward into a function call/expression.
4 %+% DepthProc Adds plots
4 %+% Jmisc Concatenate two strings
4 %+% lava Concatenation operator
4 %+% stringi Concatenate Two Character Vectors
5 %in% discreteRV Generic method for in operator function
5 %in% flowCore Filter-specific membership methods
6 %s% matrixcalc Direct sum of two arrays
6 %s% Rgnuplot String concatenation operator
7 %!in% operator.tools Logical Operator: NOT IN
7 %!in% operators Not in
8 %~% operators Pattern matching operators
8 %~% reportr Test a character vector for a match against a regular expression
9 %<% scidb Masking comparison methods from package 'scidb'
9 %<% stringi Compare Strings with or without Collation
9 %<% TeachingDemos Less than or Less than and equal operators that can be chained

A complete list of free operators (全自由演算子の一覧)

Op Package Description
%same% BayesFactor Compare two objects to see if they are the 'same', for some loose
%termin% BayesFactor Find a model term in a vector of
%btwn% BBmisc Check if some values are covered by the range of the values in a
%nin% BBmisc Simply a negated 'in' operator.
%nin% DescTools Find Matching (or Non-Matching) Elements
%nin% Hmisc Find Matching (or Non-Matching) Elements
%nin% memisc Negative Match
%inInterval% BEQI2 Test if a Value is in an Interval
%*% bigalgebra %*%,big.matrix,big.matrix-method
%*% compositions inner product for matrices and vectors
%*% compositions inner product for datasets with a vector space structure
%*% compositions inner product for datasets with vector scale
%*% gmatrix Matrix Multiplication
%*% HiPLARM Matrix Multiplication of two matrices using GPU or multi-core
%*% kinship Basic Linear Algebra for classes bdsmatrix and
%*% Matrix Matrix (Cross) Products (of Transpose)
%*% orientlib %*%,orientation,orientation-method
%*% quaternions Linear Algebra with quaternions
%>% dendextend Pipe an object forward into a function call/expression.
%>% ggvis Pipe graphics
%>% gmailr Pipe statements
%>% magrittr Pipe an object forward into a function call/expression.
%+% DepthProc Adds plots
%+% Jmisc Concatenate two strings
%+% lava Concatenation operator
%+% stringi Concatenate Two Character Vectors
%c% DescTools Concatenates two strings without any separator.
%like% DescTools Like operator
%overlaps% DescTools Determines If And How Extensively Two Date Ranges Overlap
%AND% discreteRV Compute the logical AND of two events
%in% discreteRV Generic method for in operator function
%in% flowCore Filter-specific membership methods
%OR% discreteRV Compute the logical OR of two events
%dorng% doRNG Reproducible Parallel Foreach Backend
%contains% dostats Does a table contain a value
%SplitOn% favir Split a character type at the given substring
%on% flowCore Methods for Function %on% in Package 'flowCore'
%must% futile.paradigm Add post-assertion validations to a function to
%when% futile.paradigm Add guards to a function to define the
%._.% labeledLoop Labeled loop and break
%as% lambda.r Define functions and type constructors in lambda.r
%isa% lambda.r Functions for duck typing
%ni% lava Matching operator (x not in y) oposed to the '%in%'-operator (x in y)
%m+% lubridate Add and subtract months to a date without exceeding the last day
%within% lubridate Tests whether a date or interval falls within an interval
%s% matrixcalc Direct sum of two arrays
%s% Rgnuplot String concatenation operator
%!in% operator.tools Logical Operator: NOT IN
%!in% operators Not in
%-~|% operators Remove a pattern from a character vector
%/~% operators Divide by a pattern
%+=% operators Plus Equal Operators
%<<% operators Read or write an R object to/from a file
%|% operators Pipe an R object to a unix command
%~% operators Pattern matching operators
%~% reportr Test a character vector for a match against a regular expression
%~|% operators Regular expression filters
%but% operators Modification of function arguments
%o~% operators Only keeps the macthing part of a regular expression
%of% operators Is an object of a given class
%without% operators Remove certain elements from a vector
%x=% operators Creates string decorators by repeating a pattern
%k% opm Query metadata keys
%q% opm Query metadata
%grep% osmar Binary operators for grep-like functions
%>>% pipeR Pipe an object forward
%--% powerr Binary operator %-%
%.*% powerr Binary operator %.*%
%**% powerr Binary operator %**%
%++% powerr Binary operator %++%
%<a-% pryr Create an active binding.
%<c-% pryr Create a constant (locked) binding.
%<d-% pryr Create an delayed binding.
%.% pvar Concatenate strings
%&% qdap qdap Chaining
%l*% qdapTools Hash/Dictionary Lookup
%append% RecordLinkage Concatenate comparison patterns or
%or% rex Or
%out% rmngb The Opposite of '%in%'
%^% rmutil of a Matrix
%and% RQDA Binary operations of some types of RQDA objects
%Q-% RSpincalc Quaternion subtraction
%Q.% RSpincalc Quaternion dot product
%Q*% RSpincalc Quaternion multiplication
%Q/% RSpincalc Quaternion division
%Q+% RSpincalc Quaternion addition
%<% scidb Masking comparison methods from package 'scidb'
%<% stringi Compare Strings with or without Collation
%<% TeachingDemos Less than or Less than and equal operators that can be chained
%tt% STAR Time Transformation Using a gssanova Objet
%included% timetools test inclusion of 2 'POSIXcti' objects
%intersect% timetools intersects 2 'POSIXcti' objects
8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8