This is an extension of the Use of the call function NextMethod () in the accessor function in R.
Update 2017-03-25. To illustrate how this only happens when loading methods, but not when it is built into the package, I created a dummy package: https://github.com/zkamvar/inheritest#readme
Main problem:
I have a class panel that inherits another foo class, and both of them have extra arguments for the [. The foo method works sequentially, but the bar method does not work after the first use.
Error and tracking:
Error in callNextMethod(x, i, j, ..., drop): bad object found as method (class "function") 4: stop(gettextf("bad object found as method (class %s)", dQuote(class(method))), domain = NA) 3: callNextMethod(x, i, j, ..., drop) at
Additional Information:
I have a package that implements a class that depends on a class from another package. When packages are created, everything works fine, but when my package is just loaded (using devtools::load_all(".") ), I get the behavior below.
Minimum working example:
foo <- setClass("foo", representation(x = "numeric", y = "numeric")) bar <- setClass("bar", representation(distance = "numeric"), contains = "foo") setMethod(f = "[", signature = signature(x = "foo", i = "ANY", j = "ANY", drop = "ANY"), definition = function(x, i, j, ..., foo = TRUE, drop = FALSE) { if (foo) message("FOOOOOOO") if (i == "x") { return( x@x ) } else { if (i == "y") { return( x@y ) } } }) #> [1] "[" setMethod(f = "[", signature = signature(x = "bar", i = "ANY", j = "ANY", drop = "ANY"), definition = function(x, i, j, ..., bar = TRUE, drop = FALSE) { if (bar) message("BAAAAAAR") if (i == "distance") { return( x@distance ) } else { callNextMethod(x, i, j, ..., drop) } }) #> [1] "[" FOO <- new("foo", x = 1, y = 4) BAR <- new("bar", x = 1, y = 4, distance = 3) FOO["x"] #> FOOOOOOO #> [1] 1 BAR["x"] #> BAAAAAAR #> FOOOOOOO #> [1] 1 FOO["x"] #> FOOOOOOO #> [1] 1 BAR["distance"] #> BAAAAAAR #> [1] 3 BAR["x"] # fails #> BAAAAAAR #> Error in callNextMethod(x, i, j, ..., drop): bad object found as method (class "function") BAR["x", foo = FALSE] #> BAAAAAAR #> [1] 1
Note: when I passed this through reprex , the first and last BAR calls also led to errors, but I showed what I was experiencing in an interactive session. I am using R version 3.3.3