half-pass
half-pass

Reputation: 1931

How to turn quoted string input into value of a vector?

I would like to accept input from the user in a format such as:

arg_from_user = "c(1,2,3)"

and then assign the content of this string to a vector, such that:

vector = mystery_function(arg_from_user)

vector
[1] 1 2 3

What do I use in place of mystery_function?

Upvotes: 0

Views: 28

Answers (1)

akrun
akrun

Reputation: 887118

You could try

eval(parse(text="c(1,2,3)"))

Upvotes: 1

Related Questions