I didn't think GSee's or Sathish's answers went far enough because "%" does have meaning all by itself and not just in the context of the %in%
operator. It is the mechanism for defining new infix operators by users. It is a much more general issue than the virtues of the %in%
infix operator or its more general prefix ancestor match
. It could be as simple as making a pairwise "s"(um) operator:
`%s%` <- function(x,y) x + y
Or it could be more interesting, say making a second derivative operator:
`%DD%` <- function(expr, nam="x") { D(D( bquote(.(expr)), nam), nam) }
expression(x^4) %DD% "x"
# 4 * (3 * x^2)
The %
-character also has importance in the parsing of Date, date-time, and C-type format functions like strptime
, formatC
and sprintf
.
Since that was originally written we have seen the emergence of the magrittr
package with the dplyr
elaboration that demonstrates yet another use for %
-flanked operators.
So the most general answer is that %
symbols are handled specially by the R parser. Since the parser is used to process plotmath expressions, you will also see extensive options for graphics annotations at the ?plotmath
help page.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…