Skip to content
Prev 50906 / 63424 Next

match()/%in% with language objects?

Do you mean should match treat
    match(quote(foo), list(as.name("bar"), as.name("foo"))) # error
the same as
    match(list(quote(foo)), list(as.name("bar"), as.name("foo"))) # 2
?  I don't think that would be good - 'x' needs to be a list or expression
in the length!=1 cases, so it should be one in all cases.

On the other hand it would be nice to fix up things like
  > list(list(quote(foo)), quote(list(foo))) %in% list(quote(list(foo)))
  [1] TRUE TRUE
either by using calls to identical() in the match/hashing code or
adding "quoteExpressions" when deparsing the language objects.
  x <- list(list(quote(foo)), quote(list(foo)))
  table <- list(quote(list(foo)))
  x %in% table
  #[1] TRUE TRUE
  lapply(x, deparse) %in% lapply(table, deparse)
  #[1] TRUE TRUE
  lapply(x, deparse, control="quoteExpressions") %in% lapply(table,
deparse, control="quoteExpressions")
  #[1] FALSE  TRUE

duplicated() already seems to do the right thing in that case:
  duplicated(x)
  #[1] FALSE FALSE
  duplicated(x[c(1,2,1)])
  #[1] FALSE FALSE  TRUE





Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Wed, Aug 26, 2015 at 1:54 AM, Martin Maechler <maechler at stat.math.ethz.ch