When defining an R functions, I sometimes miss that it relies on objects from the enclosing environment. Something like:
a <- 1
fn <- function(x) x + a
If this happens unintentionally, it can lead to problems which are difficult to debug.
Is there a simple way to test whether fn
uses objects form the enclosing environment?
Something like:
test(fn=fn, args=list(x=1))
## --> uses 'a' from enclosing environment of 'fn'
Aucun commentaire:
Enregistrer un commentaire