From ggrothendieck at gmail.com  Thu Oct 26 12:38:01 2006
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Thu, 26 Oct 2006 06:38:01 -0400
Subject: [Rd] how to determine if a function's result is invisible
In-Reply-To: <45408DDB.6060308@sciviews.org>
References: <971536df0610251714u451cf80fy80bf38cb2f130734@mail.gmail.com>
	<454023EA.4020403@stats.uwo.ca>
	<971536df0610252002s46ef72b2n32df3e180a49e990@mail.gmail.com>
	<45403561.1000808@stats.uwo.ca>
	<971536df0610260226o55726354j8cbdfa5af07ae508@mail.gmail.com>
	<45408DDB.6060308@sciviews.org>
Message-ID: <971536df0610260338i613f2f79n6f87b388b171246@mail.gmail.com>

On 10/26/06, Philippe Grosjean <phgrosjean at sciviews.org> wrote:
>
>
> > On 10/26/06, Duncan Murdoch <murdoch at stats.uwo.ca> wrote:
> [...]
> >> Actually, there is a way, but it's undocumented (i.e., use at your own
> >> risk).  It's the eval.with.vis function.  This is an internal function
>
> Yes... and there are three problems here:
> 1) To spot the undocumented function one is looking for,
> 2) To figure out how to use it,
> 3) To rewrite your code regularly if you maintain packages that use
> several of such undocumented functions. This is the case of many R GUI
> projects... and one reason why staying up-to-date with the new versions
> of R (every 6 months) is a nightmare for these GUIs!
>
> For instance, I use eval.with.vis() in the latest version of svSockets
> package in the SciViews bundle, but I am afraid to release it on CRAN
> because I know of the nightware I will face if this function (silently)
> changes its behavior in subsequent versions of R.
>
> I guess there is no solution to this problem, since there is certainly a
> good reason for keeping portions of R code undocumented (and thus
> flagged as :" use-it-at-your-own-risk!"), but it does not eases our life!
>
> Best,
>
> Philippe Grosjean
>
> >> that is used within source() and capture.output(); you'll have to guess
> >> from the usage there what the args are.   But here's an F that does
> >> something close to what you want:
> >>
> >>  > fix(F)
> >>  > f <- function() 1
> >>  > g <- function() invisible(1)
> >>  >
> >>  > F <- function (expr)
> >> + {
> >> +     expr <- substitute(expr)
> >> +     pf <- parent.frame()
> >> +     tmp <- .Internal(eval.with.vis(expr, pf,
> >> +         baseenv()))
> >> +     tmp
> >> + }
> >>  > F(f())
> >> $value
> >> [1] 1
> >>
> >> $visible
> >> [1] TRUE
> >>
> >>  > F(g())
> >> $value
> >> [1] 1
> >>
> >> $visible
> >> [1] FALSE
> >>
> >>
>
>

I will be using it in the next version of the gsubfn package and am also
considering it for an application in the dyn package too so that makes
two or three packages already.  I think it would be a good idea to make it
or equivalent generally available in R.




[Rd] how to determine if a function's result is invisible
Gabor Grothendieck