Thanks for this explanation - it's useful, and I now understand (and like!) your strategy.  However, I think it would be better separated into its own function, like:

```R
expr_to_fun <- function(x) {
  expr <- substitute(x)
  res <- force(x)

  if (is.function(res)) {
    list(f = res, val = res())
  } else {
    f <- eval.parent(substitute(function() expr))
    list(f = f, val = res)
  }
}

expr_to_fun(function() runif(10))
expr_to_fun(runif(10))
```

then that can easily be tested independently of `r*ply`.