Dipterix,
I think delayedAssign() example you posted does what you want - if you don't
assign the environment, it will be garbage-collected. If you fetch the value,
it will be evaluated. However, I think what you meant is to have the result in
one specific delayed symbol so:
a <- function() {
Sorry I think I intended to say that
1. the expressions within `delayed` don’t have to be executed if not assigned,
and
2. the enclosing runtime environment that is potentially referenced by the
objects within delayed() can be released immediately either the returned values
are referenced or
> the `delayed` object is ready to be garbage collected if not assigned
immediately.
I am not sure what is meant here. Any object (at the R code level) is
ready to be garbage collected if not given a name or is not part of an
object with a name. Do you mean a 'delayed' component of a list
should
> This is not quite true. The value, even when invisible, is captured by
> .Last.value, and
>
> > f <- function() invisible(5)
> > f()
> > .Last.value
> [1] 5
I understand .Last.value will capture the function returns, but that only
happens in the top-level... I guess?
In the followings co
You can play with the idea by returning an environment that contains
delayed assignments. E.g.,
> f <- function(x) {
+delayedAssign("eval_date", { cat("Evaluating 'date'\n"); date()})
+delayedAssign("sum_x", { cat("Evaluating 'sum_x'\n"); sum(x)})
+environment()
+ }
> fx <- f(1:10)
>
Hi Dipterix,
On Fri, Oct 28, 2022 at 1:10 PM Dipterix Wang
wrote:
> Hi,
>
> I was wondering if it is a good idea to delay the evaluation of expression
> within invisible(), just like data()/delayedAssign()?
>
> The idea is a function might return an invisible object. This object might
> not be