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.:

  foo(x=3, y=2*x)   # this won't work

I want the above to be equivalent to

foo <- function(x=y, y=2*x)

But I to not want to respecify foo() but rather pass the a new  
function during the call (here 2*x) that will be used to calculate y.
This problem arised in the following situation:

foo <- function(x=background, y=checkcolor(background))

Here a background color is given and checkcolor() will return a color  
for the text that gives a good contrast to the background color.
Now, I would like to change the function used for this step, like:

foo <- function(x=background, y=checkcolorNew(background))

but to do this within the call: The solution is use know is the  
following:

foo <- function(x=y, y=fun(x), fun=function(x) x*2) cat (x,y)
foo(2)
and with modified funtion to calculate y:
foo(2, , fun=function(x) 20*x)

So I use the extra argument fun. Before I tried to do it without the  
extra argument, though I still do not know if it is possible.
If it is basically was my question if it is.

Hope this makes it clearer,
Thanks in advance,
Mark




Am 14.03.2010 um 15:43 schrieb 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 be able to modify it like below:
>>
>> foo(y=x/3)
>
>
> You really want to *modify* the list of formal arguments like that  
> or do you want to *call* it like that?
>
>
>> Of course, this does not work as the object x is not known.
>
> Right.
>
>
>> Still I
>> would like to be able to pass a function as an argument that is
>> evaluated using lazy loading.
>
> If you rephrase your question more exactly and give a more  
> elaborated example where you want to make use of it, we may be able  
> to help, but I do not want to answer based on speculations here.
>
> Best,
> Uwe Ligges
>
>
>
>> Can someone help?
>>
>> Thanks,
>> Mark
>> –––––––––––––––––––––––––––––––––––––––
>> Mark Heckmann
>> Dipl. Wirt.-Ing. cand. Psych.
>> Vorstraße 93 B01
>> 28359 Bremen
>> Blog: www.markheckmann.de
>> R-Blog: http://ryouready.wordpress.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.

–––––––––––––––––––––––––––––––––––––––
Mark Heckmann
Dipl. Wirt.-Ing. cand. Psych.
Vorstraße 93 B01
28359 Bremen
Blog: www.markheckmann.de
R-Blog: http://ryouready.wordpress.com





        [[alternative HTML version deleted]]

______________________________________________
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