Closed RobinHankin closed 3 years ago
In the Matrix
package it says:
##--- Something else: Allow v[ <sparseVector> ] -- exactly similarly:
if(FALSE) { ## R_FIXME: Not working, as internal "[" only dispatches on 1st argument
setMethod("[", signature(x = "atomicVector", i = "lsparseVector"),
function (x, i, j, ..., drop) x[sort.int(i@i[i@x])])
setMethod("[", signature(x = "atomicVector", i = "nsparseVector"),
function (x, i, j, ..., drop) x[sort.int(i@i)])
}
so that's what is wrong: R only dispatches on the first argument. But that is not a problem here because I only need extraction methods where both x
and i
are disord
objects.
I have a new S4 class "foo" and want to use it to extract elements from a vector. But see the following:
Desired behaviour is for "letters[a]" on the last line to dispatch to the "hello" function, but I get this error instead. What is wrong with my understanding?