Я немного озадачен следующей ситуацией. Я хотел бы проверить, определяется ли переменная b
, переданная в функцию foo()
, из вызывающей среды. Это последовательность вызовов
> foo <- function(a,b) {print(a); if (exists(deparse(substitute(b)),parent.frame())) print(b)}
> foo(1,b) ## b is not defined, so this makes sense
[1] 1
> b <- 'b'
> foo(1,b) ## b is defined, so this makes sense too
[1] 1
[1] "b"
> foo(1,'b') ## here I would think the variable b is defined in the function, but it's not
[1] 1
Как проверить, что последний вызов foo(1,'b')
является допустимым?