R/Annotated-class.R

### =========================================================================
### Annotated objects
### -------------------------------------------------------------------------

setClass("Annotated", representation("VIRTUAL", metadata = "list"))

setGeneric("metadata", function(x, ...) standardGeneric("metadata"))
setMethod("metadata", "Annotated",
          function(x) {
              if (is.null(x@metadata) || is.character(x@metadata))
                  list(metadata = x@metadata)
              else
                  x@metadata
          })

setGeneric("metadata<-",
           function(x, ..., value) standardGeneric("metadata<-"))
setReplaceMethod("metadata", "Annotated",
                 function(x, value) {
                     if (!is.list(value))
                         stop("replacement 'metadata' value must be a list")
                     if (!length(value))
                         names(value) <- NULL # instead of character()
                     x@metadata <- value
                     x
                 })

Try the S4Vectors package in your browser

Any scripts or data that you put into this service are public.

S4Vectors documentation built on Dec. 11, 2020, 2:02 a.m.