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
EDIT : as per @Tommy's comment: The evaluation actually only takes place once the argument expr is used (that's the lazy evaluation).
What is passed is a language object, not an expression. You basically nest the <-
function (with two arguments) within the st() function call, and the result of the <-
call is passed to to st. As you can see in ?assignOps
, the <-
function returns the assigned value silently. As @Josh told you already, this evaluation of the nested function takes place in the environment the function is called from.
What you do, is equivalent to
st(mean(1:10))
To see the difference, you can do:
st <- function(expr){
typeof(expr)
}
> st(aa <- 1)
[1] "double"
> st(expression(aa <- 1))
[1] "expression"
For the structure of the call, you can do:
st <- function(expr){
str(as.list(match.call()))
}
> st(mean(1:10))
List of 2
$ : symbol st
$ expr: language mean(1:10)
> st(aa <- 1)
List of 2
$ : symbol st
$ expr: language aa <- 1