a <- as_decorated(as.list(setNames(letters[1:3], LETTERS[1:3]))) attr(a$B, 'label') <- 'foo' a <- a[1:3] attributes(a) Subset Decorated
Source:R/singularity.R
sub-.decorated.RdSubsets decorated. Calls promote
internally to improve ambiguous conditional
attributes where possible.
Usage
# S3 method for class 'decorated'
x[..., .promote = getOption("yamlet_promote", TRUE)]See also
Other promote:
filter.decorated(),
promote(),
promote.data.frame(),
promote.list(),
singularity()
Other decorated:
[<-.decorated(),
[[.decorated(),
[[<-.decorated(),
as_categorical(),
as_categorical.decorated(),
merge.decorated(),
names<-.decorated()
Examples
library(magrittr)
file <- system.file(package = 'yamlet', 'extdata','phenobarb.csv')
x <- file %>% decorate
x %>% decorations(event, value)
#> - event
#> - label: type of event
#> - guide: dose, conc
#> - value
#> - label
#> - event == 'dose': dose of drug administered
#> - event == 'conc': serum phenobarbital concentration
#> - guide
#> - event == 'dose': µg/kg
#> - event == 'conc': µg/L
# Subsetting promotes automatically.
x[x$event == 'dose',] %>% decorations(event, value)
#> - event
#> - label: type of event
#> - guide: dose, conc
#> - value
#> - label: dose of drug administered
#> - guide: µg/kg
x[x$event == 'conc',] %>% decorations(event, value)
#> - event
#> - label: type of event
#> - guide: dose, conc
#> - value
#> - label: serum phenobarbital concentration
#> - guide: µg/L
# Dimension may be dropped
x[1,1]
#> [1] 1
#> attr(,"label")
#> [1] "infant identifier"
# Conventional subsetting
a <- as_decorated(as.list(setNames(letters[1:3], LETTERS[1:3])))
attr(a$B, 'label') <- 'foo'
a <- a[1:3]
attributes(a)
#> $names
#> [1] "A" "B" "C"
#>
#> $class
#> [1] "decorated" "list"
#>