making sure a function does not use a global varia

2019-01-28 05:28发布

This question already has an answer here:

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.

标签: r scope
1条回答
仙女界的扛把子
2楼-- · 2019-01-28 06:30

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"
查看更多
登录 后发表回答