Henrik Bengtsson
2015-Feb-07 17:40 UTC
[Rd] WISH: eval() to preserve the "visibility" (now value is always visible)
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
Duncan Murdoch
2015-Feb-07 17:58 UTC
[Rd] WISH: eval() to preserve the "visibility" (now value is always visible)
On 07/02/2015 12:40 PM, Henrik Bengtsson wrote:> 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] 3What's wrong with the workaround? Duncan Murdoch
Apparently Analagous Threads
- WISH: eval() to preserve the "visibility" (now value is always visible)
- Inconsistency between eval and withVisible (with patch)
- PATCH: Avoiding extra copies (NAMED bumped) with source(..., print.eval=FALSE) ...and with print.eval=TRUE?
- source, sys.source and error line numbers
- gdistance::shortestPath throws error "not a symmetric matrix"