From bill at insightful.com  Thu Oct 26 19:23:12 2006
From: bill at insightful.com (Bill Dunlap)
Date: Thu, 26 Oct 2006 10:23:12 -0700 (PDT)
Subject: [Rd] how to determine if a function's result is invisible
In-Reply-To: <454023EA.4020403@stats.uwo.ca>
References: <971536df0610251714u451cf80fy80bf38cb2f130734@mail.gmail.com>
	<454023EA.4020403@stats.uwo.ca>
Message-ID: <Pine.GSO.4.56.0610261017090.22589@durian.statsci.com>

On Wed, 25 Oct 2006, Duncan Murdoch wrote:

> On 10/25/2006 8:14 PM, Gabor Grothendieck wrote:
> > Suppose we have a function such as the following
> >
> > F <- function(f, x) f(x)+1
> >
> > which runs function f and then transforms it.  I would like the
> > corresponding function which works the same except that
> > unlike F returns an invisible result if and only if f does.
>
> I don't think there's a way to do that.  Internally there's a global
> flag called R_Visible; if it is set to zero, the value won't print.  But
>   it gets reset to 1 very easily (e.g. by adding 1 to the result of an
> invisible function), and it's not available in the API for you to write
> C code to look at it.

source(print.eval=TRUE) appears to do this by using an eval.with.vis()
function that calls a .Internal():
    eval.with.vis <- function(expr, envir = parent.frame(),
            enclos = if (is.list(envir) || is.pairlist(envir)) parent.frame() else baseenv())
            .Internal(eval.with.vis(expr, envir, enclos))
Perhaps that could be adapted for more general use.

----------------------------------------------------------------------------
Bill Dunlap
Insightful Corporation
bill at insightful dot com
360-428-8146

 "All statements in this message represent the opinions of the author and do
 not necessarily reflect Insightful Corporation policy or position."




[Rd] how to determine if a function's result is invisible
Bill Dunlap