> library(pipeR)
> f <- function(x) cat("global f")
> Pipe(0)$f()
global f
> pf <- Pipe(0)$f
> pf()
global f
> local({f <- function(x) cat("local f"); pf()})
global f
> local({f <- function(x) cat("local f"); Pipe(0)$f()})
local f
> local({f <- function(x) cat("local f"); pf2 <<- Pipe(0)$f})
> pf2()
local f
Function is determined when $ is called, rather than when the function is called. This design avoids potential confusion if the local environment accidentally contains a function having the same name.
A more careful consideration should be done to determine which design is more reasonable: the static calling mechanism (which function to call is determined when $ is called), or the dynamic calling mechanism (which function to call is determined only when the function is being called).
Consider the following example:
Function is determined when
$
is called, rather than when the function is called. This design avoids potential confusion if the local environment accidentally contains a function having the same name.A more careful consideration should be done to determine which design is more reasonable: the static calling mechanism (which function to call is determined when
$
is called), or the dynamic calling mechanism (which function to call is determined only when the function is being called).