Skip to content

setMethodReplace.. Help!

2 messages · Wolski, John Chambers

#
Hi!

Trying to reproduce some examples from "Programming with Data" page 341.
Can not reproduce it neither on R1.8.1. nor R1.9.0devel?


library(methods)
setClass("track",representation(x="numeric",y="numeric"))

setMethod("["
          ,"track"
          ,function(x,...,drop=T){
            track(x at x[...],y at y[...])
          }
          )

In method for function "[": Expanding the signature to
include omitted arguments in definition: i = "missing",
j = "missing"
Error in .MakeSignature(new("signature"), def, signature) :
        The names in signature for method (x, , ) don't match function's arguments (x, i, j, drop)

The same....
setReplaceMethod("[","track"
                 ,function(x,...,value)
                 {
                  x at y[...]=as(value,"numeric") 
                 }
                 )


Please Help.
Eryk.
#
The error message says it:  in R, the arguments for the generic function 
"[" include i and j; the method definition must include those as well. 
Do getGeneric("[") or ?"[" to see the arguments.

As has been said on the R mailing lists in the past, R is generally 
compatible with the published books, but not when there is a better 
approach.  Having the extra arguments allows methods to be based on the 
class of the row or column indices.
wolski wrote: