我想知道是否有任何方法可以覆盖R包中的任何运算符方法。
以下是该包中源代码的示例:
我想要覆盖现有包中的方法,使用:
以下是该包中源代码的示例:
setclass("clsTest", representation(a="numeric", b="numeric"))
setMethod("+", signature(x1 = "numeric", x2 = "clsTest"),
definition=function(x1, x2) {
Test = x2
Test@a = Test@a+x1
Test@b = Test@b+x1
Test
})
我想要覆盖现有包中的方法,使用:
setMethod("+", signature(x1 = "numeric", x2 = "clsTest"),
definition=function(x1, x2) {
Test = x2
Test@a = Test@a+(2*x1)
Test@b = Test@b+(2*x1)
Test
})
我正在使用R 2.15.2,有没有办法覆盖它?