Dynamically handles metadata assignment and extraction in a similar fashion for both S3 and S4 objects.
Usage
metadata2(x, which, ...)
metadata2(x, which, ...) <- value
# S4 method for class 'ANY,character'
metadata2(x, which)
# S4 method for class 'Annotated,character'
metadata2(x, which)
# S4 method for class 'ANY,character'
metadata2(x, which) <- value
# S4 method for class 'Annotated,character'
metadata2(x, which) <- value
Value
metadata2()
: Metadata. ReturnsNULL
onwhich
match failure, similar toattr()
andmetadata()
.metadata2<-()
: Modified object.
S3 class
Internally slots into attributes()
.
Attribute is also accessible via attr(object, which)
.
S4 class
Requires that object extends Annotated
class.
Internally slots into metadata()
.
Attribute is also accessible via metadata(object)[[which]]
.
Examples
## S3 ====
x <- data.frame()
metadata2(x, which = "A") <- "B"
metadata2(x, which = "A")
#> [1] "B"
attr(x, which = "A")
#> [1] "B"
## S4 (extending Annotated) ====
x <- S4Vectors::DataFrame()
metadata2(x, which = "A") <- "B"
metadata2(x, which = "A")
#> [1] "B"