Skip to content
Prev 59015 / 63424 Next

How to use `[` without evaluating the arguments.

This works as expected:

"[.foo" <- function(x, i, j) {
  sx <- substitute(x)
  si <- substitute(i)
  sj <- substitute(j)
  100 * length(sx) + 10 * length(si) + length(sj)
}

x <- 1:10
class(x) <- "foo"
x[y == z, a(x)]
#> [1] 132

Note in your implementation you ask the function evaluate the
expression. You may have been intending to recompose the calls from
the substituted values of x, i, j and evaluate this new call.

On Fri, 25 Sep 2020 at 20:02, Eeles, Christopher
<Christopher.Eeles at uhnresearch.ca> wrote:
Message-ID: <CAJmOi+MWqXY-KRAeXS7oUtUcFrnHm+dTF0gx_Hn+dy3mDdKtQw@mail.gmail.com>
In-Reply-To: <YT1PR01MB3498221E80DC121422DC2F339F390@YT1PR01MB3498.CANPRD01.PROD.OUTLOOK.COM>