Stochastic Nonsense

Put something smart here.

Getting the Value of a Variable From a String in R

It’s often convenient to use reflection to get the value of a variable from the name as a string. In R, you can use the get function to do this.

In R :

1
2
3
4
5
blog $ R
> x = 3
> get('x')
[1] 3
>

In Ruby:

1
2
3
4
5
$ irb
irb(main):001:0> x = 3
=> 3
irb(main):002:0> eval 'x'
=> 3

though Ruby’s eval is more general, and is equivalent to eval in R allowing you to evaluate arbitrary code in a string.