A container class to manage generic attributes. Supports
named attributes with default values with methods for vectorized access.
Objects from the Class
Objects can be created by calls of the form new("attrData", defaults).
The defaults argument should be a named list containing the
initial attribute names and default values.
Slots
data:
Where custom attribute data is stored
defaults:
A named list of known attribute names and
defualt values.
Methods
attrDataItem<-
signature(self = "attrData", x = "character", attr = "character"): ...
attrDataItem
signature(self = "attrData", x = "character", attr = "missing"): ...
attrDataItem
signature(self = "attrData", x = "character", attr = "character"): ...
attrDefaults<-
signature(self = "attrData", attr = "character", value = "ANY"): ...
attrDefaults<-
signature(self = "attrData", attr = "missing", value = "list"): ...
signature(self="attrData",
x="character", value="NULL"): Remove the data associated with
the key specified by x.
Author(s)
Seth Falcon
Examples
defaultProps <- list(weight=1, color="blue", friends=c("Bob", "Alice"))
adat <- new("attrData", defaults=defaultProps)
## Get all defaults
attrDefaults(adat)
## Or get only a specific attribute
attrDefaults(adat, attr="color")
## Update default weight
attrDefaults(adat, attr="weight") <- 500
## Add new attribute
attrDefaults(adat, attr="length") <- 0
## Asking for the attributes of an element you haven't customized
## returns the defaults
attrDataItem(adat, x=c("n1", "n2"), attr="length")
## You can customize values
attrDataItem(adat, x=c("n1", "n2"), attr="length") <- 5
## What keys have been customized?
names(adat)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(graph)
Loading required package: BiocGenerics
Loading required package: parallel
Attaching package: 'BiocGenerics'
The following objects are masked from 'package:parallel':
clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
clusterExport, clusterMap, parApply, parCapply, parLapply,
parLapplyLB, parRapply, parSapply, parSapplyLB
The following objects are masked from 'package:stats':
IQR, mad, xtabs
The following objects are masked from 'package:base':
Filter, Find, Map, Position, Reduce, anyDuplicated, append,
as.data.frame, cbind, colnames, do.call, duplicated, eval, evalq,
get, grep, grepl, intersect, is.unsorted, lapply, lengths, mapply,
match, mget, order, paste, pmax, pmax.int, pmin, pmin.int, rank,
rbind, rownames, sapply, setdiff, sort, table, tapply, union,
unique, unsplit
> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/graph/attrData-class.Rd_%03d_medium.png", width=480, height=480)
> ### Name: attrData-class
> ### Title: Class "attrData"
> ### Aliases: attrData-class
> ### attrDataItem<-,attrData,character,character-method
> ### attrDataItem,attrData,character,missing-method
> ### attrDataItem,attrData,character,character-method
> ### attrDefaults<-,attrData,character,ANY-method
> ### attrDefaults<-,attrData,missing,list-method
> ### attrDefaults,attrData,missing-method
> ### attrDefaults,attrData,character-method initialize,attrData-method
> ### names,attrData-method names<-,attrData,character-method
> ### removeAttrDataItem<-
> ### removeAttrDataItem<-,attrData,character,NULL-method
> ### Keywords: classes
>
> ### ** Examples
>
> defaultProps <- list(weight=1, color="blue", friends=c("Bob", "Alice"))
> adat <- new("attrData", defaults=defaultProps)
>
> ## Get all defaults
> attrDefaults(adat)
$weight
[1] 1
$color
[1] "blue"
$friends
[1] "Bob" "Alice"
>
> ## Or get only a specific attribute
> attrDefaults(adat, attr="color")
[1] "blue"
>
> ## Update default weight
> attrDefaults(adat, attr="weight") <- 500
>
> ## Add new attribute
> attrDefaults(adat, attr="length") <- 0
>
> ## Asking for the attributes of an element you haven't customized
> ## returns the defaults
> attrDataItem(adat, x=c("n1", "n2"), attr="length")
$n1
[1] 0
$n2
[1] 0
>
> ## You can customize values
> attrDataItem(adat, x=c("n1", "n2"), attr="length") <- 5
>
> ## What keys have been customized?
> names(adat)
[1] "n1" "n2"
>
>
>
>
>
>
> dev.off()
null device
1
>