I read Hadley Wickham's Advanced R, which introduces some very good exercises. One of them asks to describe this function:
f1 <- function(x = {y <- 1; 2}, y = 0) { x + y } f1()
Can someone help me understand why it returns 3? I know that something is called lazy evaluation of input arguments and, for example, another exercise requires a description of this function
f2 <- function(x = z) { z <- 100 x } f2()
and I correctly predicted that it is 100; x gets the value of z , which is calculated inside the function, and then x is returned. However, I cannot understand what is happening in f1() .
Thanks.
r lazy-evaluation
Celdor
source share