Functional Programming in R 4 by Thomas Mailund

Functional Programming in R 4 by Thomas Mailund

Author:Thomas Mailund
Language: eng
Format: epub
ISBN: 9781484294871
Publisher: Apress


Figure 4-7Evaluating with an explicit argument

We can exploit lazy evaluation to extract expressions rather than values and evaluate them in different environments, should we choose. A full exploration of this is beyond the scope of this book, but a short example could look like this:f <- function(expr, ...) {

expr <- substitute(expr) # Turn argument into a plain expression

env <- list2env(list(...)) # Make an env from '...'

parent.env(env) <- parent.frame() # Get remaining args from caller's env

eval(expr, env) # Now evaluate the expression in the new env

}



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.