Stores a coding at the "rcoder.coding" attribute of a vector
assign_coding(vec, .coding, .bpr = TRUE)
A vector
A `coding` object
Also overwrite the "bpr.coding" attribute with the character representation of `.coding`. Used for interop with blueprintr variable decorations.
The vector with its "rcoder.coding" attribute set to `.coding`
[recode_vec()]
cdng <- coding(code("Yes", 3), code("Maybe", 2), code("No", 1))
vec <- sample(1:3, 50, replace = TRUE)
assign_coding(vec, cdng)
#> [1] 2 2 3 1 1 3 2 1 3 3 2 1 2 3 2 3 3 2 2 1 1 3 2 1 3 2 1 2 1 1 3 2 3 1 1 3 2 2
#> [39] 1 2 2 3 2 2 3 1 2 2 1 3
#> attr(,"rcoder.coding")
#> <Coding>
#> # A tibble: 3 × 5
#> link label value description missing
#> <chr> <chr> <dbl> <chr> <lgl>
#> 1 Yes Yes 3 Yes FALSE
#> 2 Maybe Maybe 2 Maybe FALSE
#> 3 No No 1 No FALSE
#> attr(,"bpr.coding")
#> [1] "coding(code(\"Yes\", 3), code(\"Maybe\", 2), code(\"No\", 1))"