首页 > 解决方案 > 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.

标签: rstringlist

解决方案


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

推荐阅读