Stores a coding at the "rcoder.coding" attribute of a vector

assign_coding(vec, .coding, .bpr = TRUE)

Arguments

vec

A vector

.coding

A `coding` object

.bpr

Also overwrite the "bpr.coding" attribute with the character representation of `.coding`. Used for interop with blueprintr variable decorations.

Value

The vector with its "rcoder.coding" attribute set to `.coding`

See also

[recode_vec()]

Examples

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))"