Skip to contents

Coerces factor guide-like attributes to 'guide'. 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 these with 'guide': i.e., to undo the effects of explicit_guide.dvec. If guide attribute is still present, the explicit attribute is removed. Otherwise the explicit element is renamed.

Usage

# S3 method for class 'factor'
implicit_guide(x, ...)

Arguments

x

factor

...

ignored

Value

factor

Examples

library(magrittr)
x <- data.frame(RACE = factor(1))
x %<>% modify(RACE, label = 'race', guide = list(white = 0, black = 1, asian = 2))
x %>% decorations
#> - RACE
#>  - label: race
#>  - guide
#>   - white: 0
#>   - black: 1
#>   - asian: 2
x %>% explicit_guide %>% decorations
#> - RACE
#>  - label: race
#>  - codelist
#>   - white: 0
#>   - black: 1
#>   - asian: 2
x %>% explicit_guide %>% implicit_guide %>% decorations
#> - RACE
#>  - label: race
#>  - guide
#>   - white: 0
#>   - black: 1
#>   - asian: 2
x %>% explicit_guide(simplify = FALSE) %>% decorations
#> - RACE
#>  - label: race
#>  - guide
#>   - white: 0
#>   - black: 1
#>   - asian: 2
#>  - codelist
#>   - white: 0
#>   - black: 1
#>   - asian: 2
x %>% explicit_guide(simplify = FALSE) %>% implicit_guide %>% decorations
#> - RACE
#>  - label: race
#>  - guide
#>   - white: 0
#>   - black: 1
#>   - asian: 2
x %<>% explicit_guide
a <- x$RACE
str(a)
#>  Factor w/ 1 level "1": 1
#>  - attr(*, "label")= chr "race"
#>  - attr(*, "codelist")=List of 3
#>   ..$ white: num 0
#>   ..$ black: num 1
#>   ..$ asian: num 2
str(a %>% implicit_guide)
#>  Factor w/ 1 level "1": 1
#>  - attr(*, "label")= chr "race"
#>  - attr(*, "guide")=List of 3
#>   ..$ white: num 0
#>   ..$ black: num 1
#>   ..$ asian: num 2