Piyush Kumar
Piyush Kumar

Reputation: 122

list inside string to list in R

I have a string:

"list(id = '1001', status = c('xyz', 'abc', 'def', 'jkl'))"

I want to convert it to:

list(id = '1001', status = c('xyz', 'abc', 'def', 'jkl'))

Any help would be greatly appreciated.

Upvotes: 1

Views: 37

Answers (1)

akrun
akrun

Reputation: 886938

We can just do eval(parse

out <- eval(parse(text = "list(id = '1001', status = c('xyz', 'abc', 'def', 'jkl'))"))

-output

out
$id
[1] "1001"

$status
[1] "xyz" "abc" "def" "jkl"

With dput, can get the structure

dput(out)
list(id = "1001", status = c("xyz", "abc", "def", "jkl"))

Upvotes: 2

Related Questions