Can somebody please explain what happens when an expression is evaluated in system.time
? In particular, why are any variables that are declared in the ex
I think the expr
is evaluated before handling that to the function. POC example:
> st <- function(expr){
+ eval(parse(text=expr))
+ }
>
> st('aa <- 1')
> aa
Error: object 'aa' not found
So I think the function gets expr
as only aa
. Another example:
> st <- function(expr){
+ str(expr)
+ }
>
> st(aa <- 1)
num 1
I might be wrong, it is rather an intuition :) But thanks, that is a good puzzle!
Update:
> system.time(a <- 1)
user system elapsed
0 0 0
> a
[1] 1
> rm(a)
> fn <- function() a <- 1
> system.time(fn())
user system elapsed
0 0 0
> a
Error: object 'a' not found