Skip to contents

The compact form is a single string with the value and label corresponding to a given option separated with a comma, and options separated with a vertical bar, e.g. "value1, Label 1 | value2, Label 2 | value3, Label 3"

Usage

generate_coded_options(x, type_of_values = c("int", "string", "names"))

Arguments

x

A vector of labels

type_of_values

Type of values to generate corresponding to each possible label. Either integers ("int"), strings ("string"), or take values from the element names of x ("names").

Value

A string giving the possible values and corresponding labels for a given variable, in compact format

Examples

x <- c("Value #1", "Value #2", "Value #3")
names(x) = c("val1", "val2", "val3")

# use specified names as values
generate_coded_options(x, type_of_values = "names")
#> [1] "val1, Value #1 | val2, Value #2 | val3, Value #3"

# generate integer values
generate_coded_options(x, type_of_values = "int")
#> [1] "1, Value #1 | 2, Value #2 | 3, Value #3"

# generate string values
generate_coded_options(x, type_of_values = "string")
#> [1] "value_1, Value #1 | value_2, Value #2 | value_3, Value #3"