[R] `mapply(function(x) function() x, c("a", "b"))$a()' returns `"b"'

Casper Ti. Vector caspervector at gmail.com
Thu May 3 17:55:53 CEST 2012


Thank you very much, though I still don't quite undertdand the
explanation :)

Nevertheless, I just found a seemingly simple (at least quiker to type)
solution after try-and-error:
    eval(mapply(function(x) {x; function() x}, c("a", "b")))
Wish it may help future readers.

On Thu, May 03, 2012 at 04:18:38PM +0200, Jessica Streicher wrote:
> So, to get back to mapply:
> 
> eval(mapply(function(x) substitute(function() z,list(z=x)), c("a", "b"))$a)()
>  or like this:
> mapply(function(x) eval(substitute(function(i) z*i,list(z=x))), c(2,3))[[1]](2)

-- 
Using GPG/PGP? Please get my current public key (ID: 0xAEF6A134, valid
from 2010 to 2013) from a key server.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120503/4f9ea4f5/attachment.bin>


More information about the R-help mailing list