On Thu, Mar 29, 2012 at 1:02 PM, Julio Sergio <julioser...@gmail.com> wrote:
> I learnt that functions can be handled as objects, the same way the variables
> are. So, the following is perfectly valid:
>
>> f = function(a, b) {
> +    print(a)
> +    print(b)
> + }
>>
>> f1 = function(foo) {
> +    foo(1,2)
> + }
>>
>> f1(f)
> [1] 1
> [1] 2
>>
>
> I also know that operators are functions, so, I can call:
>
>> '+'(1,2)
> [1] 3
>>
>
> However, when I want to pass the '+' function to the previous f1 function, it
> doesn't work:
>
>> f1('+')
> Error en f1("+") : no se pudo encontrar la función "foo"
>>
>
> (Error in f1("+") : the function "foo" cannot be found)
>
> Do you have any comments on this?
>

See ?match.fun

There is also an enhanced version, match.funfn, in the gsubfn package.


-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

______________________________________________
R-help@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.

Reply via email to