如何编辑 R S4 对象摘要的代码?

how to edit the codes for the summary of R S4 Object?

我最近想发布一个包含 S4 对象的新包。当我得到对象时,将显示插槽。结果列表太大。我想咨询如何获取R S4 Object的summary?

只列出这个:

对象

描述信息

xxxx xxx

元数据 ...

但不是这个:

对象

插槽 1 插槽 2 ...

谢谢! 嘻嘻

如果您希望 S4 对象的自定义行为,您将需要为函数 printshowsummary 编写方法。例如

## define a simple class for example purposes
myClass <- setClass("myclass",slots=c(x="numeric"))
## now write a method for the print method that uses my class
setMethod("print","myclass",function(x)cat("a myclass object with value ",x@x))
## make an example object
z <- myClass(x=1)
## now print it --- it uses the method defined above
print(z)

show 是在命令行中键入对象名称时隐式调用的内容。 printsummary 通常由用户显式调用。