高度なプログラミング言語では、任意のクラスのパブリック関数は、このクラス (オブジェクト) のインスタンスの呼び出しによって実行できます。たとえばa=new Foo(); a.somePublicFunction();、R でこのプログラミング パラダイムを使用したい場合は、次のコードを記述します。
setClass(Class = "Foo",
representation = representation(a="numeric")
)
Foo<-function(a=1){new("Foo",a=a)}
myFunction.Foo<-function(object){
return(object@a)
}
setGeneric("myFunction", function(object) standardGeneric("myFunction"))
setMethod("myFunction", signature = "Foo", definition = myFunction.Foo)
myFunctionで簡単にオーバーライドできるのはなぜmyFunction<-1/3ですか? を呼び出す場合myFunction(obj)、どこでobj is an object of classFoo , the interpreter should refer tomyFunction.Foo`. Rでこの問題を処理するには?