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

2021-12-10 Thread Ivan Krylov
On Thu, 9 Dec 2021 15:47:02 +0100 Martin Maechler 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.

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

2021-12-09 Thread Martin Maechler
> Ivan Krylov > on Wed, 8 Dec 2021 16:52:00 +0300 writes: I have always learnt a lot about programming when reading other people's code .. notably if those people new what they are doing. In this case, studying R-core's `[.data.frame` and `[<-.data.frame` {or for S4 methods, the

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

2021-12-08 Thread Bert Gunter
I haven't followed this thread, so this may be stupid, but have you looked at the do.call(`[`,...) idiom? Something like: x <- array(1:8, c(2,2,2)) > x , , 1 [,1] [,2] [1,]13 [2,]24 , , 2 [,1] [,2] [1,]57 [2,]68 > l <- as.list(rep(TRUE, 2)) >

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

2021-12-08 Thread Ivan Krylov
Got some progress on this, but still not sure how to continue. First, a much more simple script reproducing the behaviour that confuses me: foo <- function(x, ...) structure(x, class = 'foo') `[.foo` <- function(x, i, ..., drop = TRUE) { print(sys.call()) print(match.call())

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

2021-12-02 Thread Ivan Krylov
On Thu, 02 Dec 2021 13:41:52 -0800 Jeff Newmiller wrote: > I think you need a reprex... I don't think your claim is correct as > stated. Sorry, let me try again. The following "works" for me in the sense of throwing the same error on R 3.3 and R-devel: foo <- function(x, ...) UseMethod('foo')

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

2021-12-02 Thread Jeff Newmiller
I think you need a reprex... I don't think your claim is correct as stated. On December 2, 2021 1:00:01 PM PST, Ivan Krylov wrote: >Sorry for sending an unfinished message! > >On Thu, 2 Dec 2021 23:57:11 +0300 >Ivan Krylov wrote: > >> Why can I forward missing i,j to built-in `[` > >Why can I

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

2021-12-02 Thread Ivan Krylov
Hi everyone, Suppose I've got a class 'foo' that's a matrix tagged with a vector of length() == nrow(foo): foo <- function(x, ...) UseMethod('foo') foo.matrix <- function(x, y, ...) { stopifnot( !is.recursive(y), length(y) == nrow(x),

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

2021-12-02 Thread Ivan Krylov
Sorry for sending an unfinished message! On Thu, 2 Dec 2021 23:57:11 +0300 Ivan Krylov wrote: > Why can I forward missing i,j to built-in `[` Why can I forward missing i,j to the built-in `[` method but not to user-defined methods? How can I fix this? Default i and j to TRUE? Are there less