相关疑难解决方法(0)

'show'是正常的S4泛型函数吗?

我正在尝试为我的类创建一个方法,该方法继承自data.frame.我本来希望只是从data.frame继承'show'方法,但我也可以编写自己的方法.我将我的类和'show'方法定义如下:

setClass("SCvec", representation(auth = "character",
    dev = "character",
    sensor = "character",
    channel = "character",
    starttime = "character",
    endtime = "character"),
    contains="data.frame")
setMethod("show", signature(x="SCvec"), function(x) print(x))
Run Code Online (Sandbox Code Playgroud)

当我输入showR控制台时,它会输出:

从包"方法"定义的"show"的standardGeneric

function (object) 
standardGeneric("show")
<bytecode: 0x0396bee8>
<environment: 0x0393ab60>
Methods may be defined for arguments: object
Use  showMethods("show")  for currently available ones.
(This generic function excludes non-simple inheritance; see ?setIs)
Run Code Online (Sandbox Code Playgroud)

所以看起来我不需要自己使用StandardGeneric()将它变成泛型.但是当我运行我的setMethod("show", signature(x="SCvec"), function(x) print(x))线路时,我得到了错误

Error in match.call(definition, call, expand.dots) : 
  unused argument(s) (x = c("SCvec", ""))
Run Code Online (Sandbox Code Playgroud)

我已经定义了这个方法,就像我定义任何其他方法一样.为什么这个方法定义不起作用?'show'与其他通用函数不同吗?

r show generic-function s4

4
推荐指数
1
解决办法
1524
查看次数

标签 统计

generic-function ×1

r ×1

s4 ×1

show ×1