[R] Forwarding missing arguments to the `[` method

Ivan Krylov kry|ov@r00t @end|ng |rom gm@||@com
Fri Dec 10 15:20:39 CET 2021


On Thu, 9 Dec 2021 15:47:02 +0100
Martin Maechler <maechler using stat.math.ethz.ch> wrote:

> What you should take from there:
> Do work with *both*
>     missing(drop)
> and
>     nargs()
> 
> (and more)
> in order to distinguish m[i] from m[i,] etc

Thanks for the advice! `[<-.data.frame` does make for enlightening
reading. 

I've also considered editing the call, like lm() does:

`[<-.foo` <- function(x, i, ..., value) {
	cl <- match.call(expand.dots = FALSE)
	cl[[1L]] <- quote(`[`)
	cl$value <- NULL
	x.subset <- eval(cl, parent.frame())
	# ... checks on x.subset ...
	NextMethod()
}

...but that fails _some_ of my tests (but not others) with "object
`*tmp*` not found"). Non-standard evaluation is probably not the answer
here. I'll have to handle the forms of the call with different nargs()
manually and separately.

-- 
Best regards,
Ivan



More information about the R-help mailing list