I expect this code to set plt
equal to 10:
> var = "plt"
> eval(paste0(var, "<-", 10))
[1] "plt<-10"
But instead, it returns a string.
I tried eval(as.expression(paste0(var, "<-", 10)))
and other options, but it still doesn't give the expected result.
What's wrong with the code?
If I understand your comment correctly there is no reason to dive into the shark-infested waters of
eval(parse())
. Try something like this instead:See:
?parse
. Your demo code:Update: based on @Anton's comment about the original goal - what about:
PS: I still trying to implement what the OP is after, not what he might or should be after -- that's why I used above
assign
and.GlobalEnv
, although it's not a great idea BTW.