Skip to contents

Coerces factor 'guide' attribute to something more explicit. The attribute 'guide' generally suggests a guide to interpretation of a data item, such as units, formats, codelists, and encodings. The idea here is to replace 'guide' with something explicit in case required downstream. Generally a codelist is expected, but not enforced.

Usage

# S3 method for class 'factor'
explicit_guide(
  x,
  ...,
  overwrite = getOption("yamlet_explicit_guide_overwrite", TRUE),
  simplify = getOption("yamlet_explicit_guide_simplify", TRUE),
  expand = getOption("yamlet_expand_codelist", TRUE)
)

Arguments

x

factor

...

named arguments passed to as_yamlet, explicit_guide, and decorate; un-named arguments ignored

overwrite

whether to overwrite attributes

simplify

whether to remove guide attribute

expand

whether to expand empty guide list using sorted unique values. NA likely excluded.

Value

factor

Examples

library(magrittr)
x <- data.frame(
 ID = as_dvec(1),
 SEX = factor(1)
)
x %<>% modify(SEX, label = 'sex', guide = list(female = 0, male = 1))
x %>% decorations
#> - ID: []
#> - SEX
#>  - label: sex
#>  - guide
#>   - female: 0
#>   - male: 1
x %>% explicit_guide %>% decorations
#> - ID: []
#> - SEX
#>  - label: sex
#>  - codelist
#>   - female: 0
#>   - male: 1
x %>% explicit_guide(SEX) %>% decorations # limit scope
#> - ID: []
#> - SEX
#>  - label: sex
#>  - codelist
#>   - female: 0
#>   - male: 1
x %$% SEX %>% explicit_guide
#> [1] 1
#> attr(,"label")
#> [1] sex
#> attr(,"codelist")
#> attr(,"codelist")$female
#> [1] 0
#> 
#> attr(,"codelist")$male
#> [1] 1
#> 
#> Levels: 1