Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

making sure a function does not use a global variable [duplicate]

Tags:

scope

r

This maybe a bit converse to similar questions. I would like R to abort\warn if anywhere in the code, a function uses a variable in a parent environment. Is there some base option to achieve that? I would like a solution that is general for a session, not a particular check. Thank you.

like image 521
Elad663 Avatar asked Jan 20 '14 22:01

Elad663


1 Answers

There is a function findGlobals in the codetools package. Maybe this is helpful:

library(codetools)
x <- "global"
foo <- function() x

foo()
[1] "global"

findGlobals(foo)
[1] "x"
like image 105
Mark Heckmann Avatar answered Sep 22 '22 23:09

Mark Heckmann