Skip to content
Prev 49854 / 63424 Next

WISH: eval() to preserve the "visibility" (now value is always visible)

Sorry to intervene.

Argument passed to 'eval' is evaluated first.
So,
eval(x <- 2)
is effectively like
{ x <- 2; eval(2) } ,
which is effectively
{ x <- 2; 2 } .
The result is visible.

eval(expression(x <- 2))
or
eval(quote(x <- 2))
or
evalq(x <- 2)
gives the same effect as
x <- 2 .
The result is invisible.

In function 'eval2',
res <- eval(withVisible(expr), envir=envir, ...)
is effectively
res <- withVisible(expr) .

-------------------

Would it be possible to have the value of eval() preserve the
"visibility" of the value of the expression?


"PROBLEM":

# Invisible
# Visible
[1] 2

"TROUBLESHOOTING":
$value
[1] 1
$visible
[1] FALSE
$value
[1] 2
$visible
[1] TRUE


WORKAROUND:
eval2 <- function(expr, envir=parent.frame(), ...) {
  res <- eval(withVisible(expr), envir=envir, ...)
  value <- res$value
  if (res$visible) value else invisible(value)
}
[1] 2
[1] 3

/Henrik