Eval vs Get
I’ve been fighting damn scoping issues lately and finally sat down to figure out what works and when. Documenting some of them here
The lessons I’ve learned from this:
eval(a, envir = ... )
DOES NOT WORK!- Instead, do
eval(str2lang("a"), envir = ...)
eval.parent(a)
DOES NOT WORK!eval.parent(str2lang("a"))
works and SKIPS GENERIC!get("a", envir = ...)
seems to always work as expected
So to summarize, I think get
is always a safer option than eval
. In
addition, get
is much faster:
|
|
Obviously this doesn’t cover more advanced situations, like evaluating full calls, but I’m still working on puzzling all that out.
Here’s the sample code I used to evaluate this:
|
|
This produces:
|
|
Home | Back to blog