From hb at biostat.ucsf.edu  Sat Feb  7 18:40:25 2015
From: hb at biostat.ucsf.edu (Henrik Bengtsson)
Date: Sat, 7 Feb 2015 09:40:25 -0800
Subject: [Rd] WISH: eval() to preserve the "visibility" (now value is always
	visible)
Message-ID: <CAFDcVCQBgYK3NRWBAHwXV5YAjCMu4gFzBGNw4C8K=oOKBXbmsA@mail.gmail.com>

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


"PROBLEM":

# Invisible
> x <- 1

# Visible
> eval(x <- 2)
[1] 2


"TROUBLESHOOTING":
> withVisible(x <- 1)
$value
[1] 1
$visible
[1] FALSE

> withVisible(eval(x <- 2))
$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)
}

> x <- 1
> eval(x <- 2)
[1] 2
> eval2(x <- 3)
> x
[1] 3

/Henrik



[Rd] WISH: eval() to preserve the "visibility" (now value is always visible)
Henrik Bengtsson