updateObject             package:Biobase             R Documentation

_U_p_d_a_t_e _a_n _o_b_j_e_c_t _t_o _i_t_s _c_u_r_r_e_n_t _c_l_a_s_s _d_e_f_i_n_i_t_i_o_n

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

     These generic functions return an instance of 'object' updated to
     its current class definition (or to the class definition of
     'template', in the case of 'updateObjectTo').

     Updating objects is primarily useful when an object has been
     serialized (e.g., stored to disk) for some time (e.g., months),
     and the class definition has in the mean time changed. Because of
     the changed class definition, the serialized instance is no longer
     valid.

     'updateObject' requires that the class of the returned object be
     the same as the class of the argument 'object', and that the
     object is valid (see 'validObject'). By default, 'updateObject'
     has the following behaviors:

     '_u_p_d_a_t_e_O_b_j_e_c_t(_A_N_Y, ..., _v_e_r_b_o_s_e=_F_A_L_S_E)' By default, 'updateObject'
          uses heuristic methods to determine whether the object should
          be the `new' S4 type (introduced in R 2.4.0), but is not. If
          the heuristics indicate an update is required,  the
          'updateObjectFromSlots' function tries to update the object.
          The default method returns the original S4 object or the
          successfully updated object, or issues an error if an update
          is required but not possible. The optional named argument
          'verbose' causes a message to be printed describing the
          action. Arguments '...' are passed to
          'link{updateObjectFromSlots}'.

     '_u_p_d_a_t_e_O_b_j_e_c_t(_l_i_s_t, ..., _v_e_r_b_o_s_e=_F_A_L_S_E)' Visit each element in
          'list', applying 'updateObject(list[[elt]], ...,
          verbose=verbose)'.

     '_u_p_d_a_t_e_O_b_j_e_c_t(_e_n_v_i_r_o_n_m_e_n_t, ..., _v_e_r_b_o_s_e=_F_A_L_S_E)' Visit each element
          in 'environment', applying 'updateObject(environment[[elt]],
          ..., verbose=verbose)'

     'updateObjectTo' requires that the class of the returned object be
     the same as the class of the 'template' argument, and that the
     object is valid. Usually, updating proceeds by modifying slots in
     'template' with information from 'object', and returning
     'template'. Use 'as' to coerce an object from one type to another;
     'updateObjectTo' might be useful to update a virtual superclass.
     By default, 'updateObjectTo' has the following behavior:

     '_u_p_d_a_t_e_O_b_j_e_c_t_T_o(_A_N_Y-_o_b_j_e_c_t,_A_N_Y-_t_e_m_p_l_a_t_e)' Attempt
          'as(ANY-object,class(ANY-template))'.

     Sample methods are illustrated below.

     'updateObjectFromSlots(object, objclass = class(object), ...,
     verbose=FALSE)' is a utility function that identifies the
     intersection of slots defined in the 'object' instance and
     'objclass' definition. The corresponding elements in 'object' are
     then updated (with 'updateObject(elt, ..., verbose=verbose)') and
     used as arguments to a call to 'new(class, ...)', with '...'
     replaced by slots from the original object. If this fails,
     'updateObjectFromSlots' then tries 'new(class)' and assigns slots
     of 'object' to the newly created instance.

     'getObjectSlots(object)' extracts the slot names and contents from
     'object'. This is useful when 'object' was created by a class
     definition that is no longer current, and hence the contents of
     'object' cannot be determined by accessing known slots.

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

     updateObject(object, ..., verbose=FALSE)
     updateObjectTo(object, template, ..., verbose=FALSE)
     updateObjectFromSlots(object, objclass=class(object), ..., verbose=FALSE)
     getObjectSlots(object)

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

  object: Object to be updated, or for slot information to be extracted
          from.

template: Instance representing a template for updating object.

objclass: Optional character string naming the class of the object to
          be created.

 verbose: A logical, indicating whether information about the update
          should be reported. Use 'message' to report this.

     ...: Additional arguments, for use in specific update methods

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

     'updateObject' returns a valid instance of 'object'.
     'updateObjectTo' returns a valid instance of 'template'.
     'updateObjectFromSlots' returns an instance of class 'objclass'.
     'getObjectSlots' returns a list of named elements, with each
     element corresponding to a slot in 'object'.

_A_u_t_h_o_r(_s):

     Biocore team

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

     'Versions-class'

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

     ## update object, same class
     data(sample.ExpressionSet)
     obj <- updateObject(sample.ExpressionSet)

     ## generally, use 'as' to coerce objects between classes
     data(sample.eSet)
     obj <- as(sample.eSet, "MultiSet")

     setClass("UpdtA", representation(x="numeric"), contains="data.frame")
     setMethod("updateObject", signature(object="UpdtA"),
               function(object, ..., verbose=FALSE) {
                   if (verbose) message("updateObject object = 'A'")
                   object <- callNextMethod()
                   object@x <- -object@x
                   object
     })

     a <- new("UpdtA", x=1:10)
     ## See steps involved
     updateObject(a)

     removeClass("UpdtA")
     removeMethod("updateObject", "UpdtA")

