Skip to content

Seeking help to define method for show() for an S4 object

2 messages · Christofer Bogaso, Joshua Wiley

#
Hi,

Take a look at ?readLines  Also, you should use function(object) not
function(x) because of how the generic is defined.  Below is an
example.

Cheers,

Josh

setClass("MyClass", sealed = FALSE, representation(
  Slot1 = "vector",
  Slot2 = "vector"))

setMethod(f = "show", signature = "MyClass",
  definition = function(object) {
    cat("These are the values.  Please press enter to see the values.\n")
    readLines(n = 1)
    cat(object at Slot1)
  })

x <- new("MyClass", Slot1 = 1:3, Slot2 = 4:7)
x

On Mon, Jun 6, 2011 at 10:19 AM, Bogaso Christofer
<bogaso.christofer at gmail.com> wrote: