updateObject: Update an object to its current class definition

Description Usage Arguments Details Value See Also Examples

Description

updateObject is a generic function that returns an instance of object updated to its current class definition.

Usage

1
2
3
4
5
updateObject(object, ..., verbose=FALSE)

## Related utilities:
updateObjectFromSlots(object, objclass=class(object), ..., verbose=FALSE)
getObjectSlots(object)

Arguments

object

Object to be updated for updateObject and updateObjectFromSlots.

Object for slot information to be extracted from for getObjectSlots.

...

Additional arguments, for use in specific updateObject methods.

verbose

TRUE or FALSE, indicating whether information about the update should be reported. Use message to report this information.

objclass

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

Details

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:

updateObject(ANY, ..., verbose=FALSE)

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 updateObjectFromSlots.

updateObject(list, ..., verbose=FALSE)

Visit each element in list, applying updateObject(list[[elt]], ..., verbose=verbose).

updateObject(environment, ..., verbose=FALSE)

Visit each element in environment, applying updateObject(environment[[elt]], ..., verbose=verbose)

updateObject(formula, ..., verbose=FALSE)

Do nothing; the environment of the formula may be too general (e.g., R_GlobalEnv) to attempt an update.

updateObject(envRefClass, ..., verbose=FALSE)

Attempt to update objects from fields using a strategy like updateObjectFromSlots Method 1.

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. Under Method 1, 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, then Method 2 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.

Value

updateObject returns a valid instance of object.

updateObjectFromSlots returns an instance of class objclass.

getObjectSlots returns a list of named elements, with each element corresponding to a slot in object.

See Also

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
updateObject
showMethods("updateObject")
selectMethod("updateObject", "ANY")  # the default method

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

setClass("UpdtA", representation(x="numeric"), contains="data.frame")
setMethod("updateObject", "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)

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

Example output

Loading required package: parallel

Attaching package:BiocGenericsThe following objects are masked frompackage:parallel:

    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    clusterExport, clusterMap, parApply, parCapply, parLapply,
    parLapplyLB, parRapply, parSapply, parSapplyLB

The following objects are masked frompackage:stats:

    IQR, mad, sd, var, xtabs

The following objects are masked frompackage:base:

    anyDuplicated, append, as.data.frame, basename, cbind, colnames,
    dirname, do.call, duplicated, eval, evalq, Filter, Find, get, grep,
    grepl, intersect, is.unsorted, lapply, Map, mapply, match, mget,
    order, paste, pmax, pmax.int, pmin, pmin.int, Position, rank,
    rbind, Reduce, rownames, sapply, setdiff, sort, table, tapply,
    union, unique, unsplit, which.max, which.min

nonstandardGenericFunction for "updateObject" defined from package "BiocGenerics"

function (object, ..., verbose = FALSE) 
{
    if (!isTRUEorFALSE(verbose)) 
        stop("'verbose' must be TRUE or FALSE")
    result <- standardGeneric("updateObject")
    check <- list(...)$check
    if (is.null(check)) {
        check <- TRUE
    }
    else if (!isTRUEorFALSE(check)) {
        stop("'check' must be TRUE or FALSE")
    }
    if (check) {
        if (verbose) 
            message("[updateObject] Validating the updated object ... ", 
                appendLF = FALSE)
        validObject(result)
        if (verbose) 
            message("OK")
    }
    result
}
<bytecode: 0x55ef6cf775f0>
<environment: 0x55ef6cf9fd20>
Methods may be defined for arguments: object
Use  showMethods("updateObject")  for currently available ones.
Function: updateObject (package BiocGenerics)
object="ANY"
object="environment"
object="envRefClass"
object="formula"
object="list"

Method Definition:

function (object, ..., verbose = FALSE) 
{
    if (verbose) 
        message("updateObject(object=\"ANY\") default for object ", 
            "of class '", class(object), "'")
    if (length(getObjectSlots(object)) > 0L && !any(class(object) %in% 
        c("data.frame"))) {
        updateObjectFromSlots(object, ..., verbose = verbose)
    }
    else {
        object
    }
}
<bytecode: 0x55ef6cf6aa88>
<environment: namespace:BiocGenerics>

Signatures:
        object
target  "ANY" 
defined "ANY" 
Welcome to Bioconductor

    Vignettes contain introductory material; view with
    'browseVignettes()'. To cite Bioconductor, see
    'citation("Biobase")', and for packages 'citation("pkgname")'.

Object of class "UpdtA"
data frame with 0 columns and 0 rows
Slot "x":
 [1]  -1  -2  -3  -4  -5  -6  -7  -8  -9 -10

[1] TRUE
[1] TRUE

BiocGenerics documentation built on April 17, 2021, 6:01 p.m.