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

Jessica Streicher j.streicher at micromata.de
Thu May 3 15:39:08 CEST 2012


As i see it you will save the actual "text" of the function - and when you call it later on it takes the last value of x it has encountered as the value. I guess you want the x not to be saved as x, but as "a" or "b", so, as its value.

I am not sure how to do that however as of yet.


Am 03.05.2012 um 12:31 schrieb Casper Ti. Vector:

> As the title says, I want to apply a function (which itself returns
> a function) to a list (or vector), and get a list (or vector) of
> generated functions as the return value, but get unexpected result.
> 
> Anyone with an idea about the reason of this phenomenon and a correct
> way to implement the requirements? Thanks very much :)
> 
> -- 
> Using GPG/PGP? Please get my current public key (ID: 0xAEF6A134, valid
> from 2010 to 2013) from a key server.
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list