show                 package:methods                 R Documentation

_S_h_o_w _a_n _O_b_j_e_c_t

_D_e_s_c_r_i_p_t_i_o_n:

     Display the object, by printing, plotting or whatever suits its
     class.

     The function `show' exists to be specialized by methods; the
     default method calls `showDefault'.

     With library `methods' attached, methods for `show' will usually
     be invoked for automatic printing (see the details).

     The function `showDefault' allows redirection of output and
     optional use of old-style print methods, but normally will not be
     called directly.

_U_s_a_g_e:

     show(object)

     showDefault(object, printTo = stdout(), oldMethods = TRUE)

_A_r_g_u_m_e_n_t_s:

  object: Any R object

 printTo: Either a file or connection, or else `FALSE'.  In the latter
          case, the lines of text that would have been printed are
          returned as the value of the call (in a character vector with
          one element per line of output). 

oldMethods: Should old-style print methods be used for this object? 
          `TRUE' by default if called directly, but `FALSE' when called
          from the methods package for automatic printing (to avoid
          potential recursion; see the details below). 

_D_e_t_a_i_l_s:

     The `methods' package overrides the base definition of
     `print.default' to arrange for automatic printing to honor methods
     for the function `show'.  This does not quite manage to override
     old-style printing methods, since the automatic printing in the
     evaluator will look first for the old-style method.

     If you have a class `myClass' and want to define a method for
     `show', all will be well unless there is already a function named
     `print.myClass'.  In that case, to get your method dispatched for
     automatic printing, it will have to be a method for `print'.  A
     slight cheat is to override the function `print.myClass' yourself,
     and then call that function also in the method for `show' with
     signature `"myClass"'.

_V_a_l_u_e:

     `show' returns an invisible `NULL'.

     For `showDefault', if `printTo' is `FALSE', the value is a
     character vector containing the lines that would otherwise have
     been printed.

_S_e_e _A_l_s_o:

     `showMethods' prints all the methods for one or more functions;
     `showMlist' prints individual methods lists;  `showClass' prints
     class definitions. Neither of the latter two normally needs to be
     called directly.

_E_x_a_m_p_l_e_s:

     ## following the example shown in the setMethod documentation ...
     setClass("track",
              representation(x="numeric", y="numeric"))
     setClass("trackCurve", 
              representation("track", smooth = "numeric"))

     t1 <- new("track", x=1:20, y=(1:20)^2)

     tc1 <- new("trackCurve", t1)

     setMethod("show", "track",
       function(object)print(rbind(x = object@x, y=object@y))
     )
     ## The method will now be used for automatic printing of t1

     t1

       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
     x    1    2    3    4    5    6    7    8    9    10    11    12
     y    1    4    9   16   25   36   49   64   81   100   121   144
       [,13] [,14] [,15] [,16] [,17] [,18] [,19] [,20]
     x    13    14    15    16    17    18    19    20
     y   169   196   225   256   289   324   361   400

     ## and also for tc1, an object of a class that extends "track"
     tc1

       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
     x    1    2    3    4    5    6    7    8    9    10    11    12
     y    1    4    9   16   25   36   49   64   81   100   121   144
       [,13] [,14] [,15] [,16] [,17] [,18] [,19] [,20]
     x    13    14    15    16    17    18    19    20
     y   169   196   225   256   289   324   361   400

