Spaces are replaced with '_' and other non valid characters are encoded as '.' + two bit hexadecimal representation. Variables which start with an underscore or a dot are prepended with the letter 'X'. The result is sent to make.names in order to deal with reserved words.

string_to_var(str)

Arguments

str

string

Value

a syntactically valid variable name

Details

Note that strings starting with 'X.' would not be translated back correctly using var_to_string, i.e. string_to_var(var_to_string("X.saba")) would result ".saba".

Examples

string_to_var("a & b")
#> [1] "a_.26_b"
string_to_var("saba and savta")
#> [1] "saba_and_savta"
string_to_var("/home/mydir")
#> [1] "X.2Fhome.2Fmydir"
string_to_var("www.google.com")
#> [1] "www.2Egoogle.2Ecom"
string_to_var("my_variable + 3")
#> [1] "my.5Fvariable_.2B_3"
string_to_var(".hidden variable")
#> [1] "X.2Ehidden_variable"
string_to_var("NULL")
#> [1] "NULL."