user2183336
user2183336

Reputation: 655

String object value evaluated as expression

I have a string variable and I would like to evaluate its value as an expression using expression()

Example:

>expression("Text")
expression("Text")

>a <- "Text"
>expression(a)
expression(a)

I want to do something to make expression(a) evaluate to expression("Text").

Upvotes: 1

Views: 41

Answers (1)

StefanK
StefanK

Reputation: 2180

maybe you could write why you need it?

Because what you want makes no sense to me.

Type

?expression

and you will see:

expression returns a vector of type "expression" containing its arguments (unevaluated)

You would have to rewrite the function to make it do what you want.

If you wanted to fake it, you would do something like this (not recommended :) ):

paste("expression(", a, ")", sep="")

edit: From ?expression you can see at the bottom, that as.expression(a) is what you needed

as.expression attempts to coerce its argument into an expression object

Upvotes: 2

Related Questions