Associative array from string
I would like to create an associative array in R from a string like "key1=values1;key2=value2". I know this can be done by double splitting and building the array manually but i was wondering if there's already something i can work with.
Using an environment as the "associative array" provides a straightforward solution.
string <- "key1=99; key2=6" # Create an environment which will be your array env <- new.env() # Assign values to keys in the environment, using eval(parse()) eval(parse(text=string), envir=env) # Check that it works: ls(env) #  "key1" "key2" env$key1 #  99 as.list(env) # $key1 #  99 # $key2 #  6