Re: [R] passing a function as an argument using lazy loading

2010-03-14 Thread Uwe Ligges
On 10.03.2010 13:26, Mark Heckmann wrote: I have the following function that makes use of lazy loading. I guess you mean *lazy evaluation* rather than *lazy loading* (as used in loading functions or data from the package databases). foo - function(x=2*y, y=x/2) cat(x,y) Now I want to

Re: [R] passing a function as an argument using lazy loading

2010-03-14 Thread Mark Heckmann
Yes. I meant lazy evaluation :) I will try to clarify what I mean. I have a function foo and in its arguments use a reference to another argument, like: foo - function(x=y, y=x) I would like to specify the function in a way it is possible to change the way the argument y is evaluated. e.g.:

Re: [R] passing a function as an argument using lazy loading

2010-03-14 Thread Duncan Murdoch
On 14/03/2010 4:33 PM, Mark Heckmann wrote: Yes. I meant lazy evaluation :) I will try to clarify what I mean. I have a function foo and in its arguments use a reference to another argument, like: foo - function(x=y, y=x) I would like to specify the function in a way it is possible to

Re: [R] passing a function as an argument using lazy loading

2010-03-14 Thread Gabor Grothendieck
Try this: foo2 - function(x=2*y, y=x/2) eval(substitute(cat(x,y,\n))) foo2(x = 1, y = x/3) 1 0.333 foo2(x = y/2, y = 10) 5 10 On Wed, Mar 10, 2010 at 7:26 AM, Mark Heckmann mark.heckm...@gmx.de wrote: I have the following function that makes use of lazy loading. foo - function(x=2*y,

[R] passing a function as an argument using lazy loading

2010-03-10 Thread Mark Heckmann
I have the following function that makes use of lazy loading. foo - function(x=2*y, y=x/2) cat(x,y) Now I want to be able to modify it like below: foo(y=x/3) Of course, this does not work as the object x is not known. Still I would like to be able to pass a function as an argument that is