Skip to contents

Promotes attributes of list-like objects. For the plural attributes of each element, any singularity is promoted to the sole attribute. Reserved attributes are untouched. Methods filter.decorated and [.decorated automatically attempt to promote attributes for all elements.

Usage

# S3 method for class 'list'
promote(
  x,
  ...,
  .reserved = getOption("yamlet_promote_reserved", c("class", "levels", "labels",
    "names"))
)

Arguments

x

list, or list-like

...

indicated elements

.reserved

attributes to leave untouched

Value

same class as x

Examples

library(magrittr)
file <- system.file(package = 'yamlet', 'extdata','phenobarb.csv')
x <- file %>% decorate

# Note that there are two elements each for value label and value guide.
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

# After filtering, only one set is relevant.
# promote() identifies and retains such.
x %>% dplyr:::filter.data.frame(event == 'dose') %>% decorations(value)
#> - value
#>  - label
#>   - event == 'dose': dose of drug administered
#>   - event == 'conc': serum phenobarbital concentration
#>  - guide
#>   - event == 'dose': µg/kg
#>   - event == 'conc': µg/L
x %>% dplyr:::filter.data.frame(event == 'dose') %>% promote %>% decorations(value)
#> - value
#>  - label: dose of drug administered
#>  - guide: µg/kg

# If for some reason we do a partial promote, value attributes are unaffected.
# Nonsense example:
x %>% dplyr:::filter.data.frame(event == 'dose') %>% promote(event) %>% decorations(value)
#> - value
#>  - label
#>   - event == 'dose': dose of drug administered
#>   - event == 'conc': serum phenobarbital concentration
#>  - guide
#>   - event == 'dose': µg/kg
#>   - event == 'conc': µg/L

# However, the 'decorated' method for filter() calls promote() internally.
x %>% filter(event == 'dose') %>% decorations(value)
#> - value
#>  - label: dose of drug administered
#>  - guide: µg/kg