, @Pop , . , , match - . match ,
setGeneric("match", signature=c("x", "table"))
setMethod("match", c(x="CAttribute", table="CAttribute"),
function(x, table, nomatch = NA_integer_, incomparables = NULL)
{
match(getName(x), getName(table), nomatch=nomatch,
incomparables=incomparables)
})
, , , match (, %in%), . - %in%
setGeneric("%in%")
setMethod("%in%", c("CAttribute", "CAttribute"),
function(x, table)
{
match(x, table, nomatch=0L) > 0L
})
, , R " ", == , , ?Compare
setMethod("Compare", c(e1="CAttribute", e2="CAttribute"),
definition=function(e1, e2)
{
callGeneric(getName(e1), getName(e2))
})
, , ==, getName() .
CAttribute <- setClass("CAttribute", representation(name="character"))
getName <- function(x) x@name
CAttribute(name="foo") %in% CAttribute(name=c("foo", "bar"))
## [1] TRUE
CAttribute(name="foo") == CAttribute(name=c("foo", "bar"))
## [1] TRUE FALSE
, , , R ; , , , .
library(microbenchmark)
microbenchmark(f0=CAttribute(name=rep("A", 1000)),
f1=replicate(1000, CAttribute(name="A")),
times=5)
## Unit: microseconds
## expr min lq median uq max neval
## f0 298.82 306.435 309.681 311.891 334.687 5
## f1 264214.85 277728.310 286446.876 300839.340 301080.928 5
- -, , , "match, CAttribute, list-method".