次の問題があります(コードは以下にあります):2つのS4クラスがあり、A
とで指定できますB
。このB
クラスには、という名前のAタイプオブジェクトのリストがありますa.list
。A
クラスには、という名前のメソッドがありますtest()
。次に、A
と呼ばれるタイプのオブジェクトとa
、タイプB
のオブジェクトを作成し、そのオブジェクトをのリストb
に挿入します。a
b@a.list
a
オブジェクトを抽出してtest
メソッドを使用すると、次のエラーが発生します。
Error en function (classes, fdef, mtable) :
unable to find an inherited method for function "test", for signature "list"
しかし、私はオブジェクトで直接メソッドを使用しa
、すべてが正常に機能します。
私が間違っていることについて何か考えはありますか?
前もって感謝します
そして今、コード:
> setClass("A", representation(a="character", b="numeric"))
> a <- new("A", a="Adolfo", b = 10)
> a
An object of class "A"
Slot "a":
[1] "Adolfo"
Slot "b":
[1] 10
> print(a)
An object of class "A"
Slot "a":
[1] "Adolfo"
Slot "b":
[1] 10
> setClass("B", representation(c="character", d="numeric", a.list="list"))
> b <- new("B", c="chido", d=30, a.list=list())
> b
An object of class "B"
Slot "c":
[1] "chido"
Slot "d":
[1] 30
Slot "a.list":
list()
> b@a.list["objeto a"] <- a
> b
An object of class "B"
Slot "c":
[1] "chido"
Slot "d":
[1] 30
Slot "a.list":
$`objeto a`
An object of class "A"
Slot "a":
[1] "Adolfo"
Slot "b":
[1] 10
> setGeneric(name="test",
+ def = function(object,...) {standardGeneric("test")}
+ )
[1] "test"
> setMethod("test", "A",
+ definition=function(object,...) {
+ cat("Doing something to an A object....\n")
+ }
+ )
[1] "test"
> b@a.list[1]
$`objeto a`
An object of class "A"
Slot "a":
[1] "Adolfo"
Slot "b":
[1] 10
> test(b@a.list[1])
Error en function (classes, fdef, mtable) :
unable to find an inherited method for function "test", for signature "list"
> test(a)
Doing something to a....
>
再度、感謝します...