Mark Heckmann
2010-Mar-10 12:26 UTC
[R] passing a function as an argument using lazy loading
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 evaluated using lazy loading. 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
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 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.
Mark Heckmann
2010-Mar-14 20:33 UTC
[R] passing a function as an argument using lazy loading
Ein eingebundener Text mit undefiniertem Zeichensatz wurde abgetrennt. Name: nicht verf?gbar URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100314/68087d92/attachment.pl>
Gabor Grothendieck
2010-Mar-14 21:20 UTC
[R] passing a function as an argument using lazy loading
Try this:> foo2 <- function(x=2*y, y=x/2) eval(substitute(cat(x,y,"\n"))) > foo2(x = 1, y = x/3)1 0.3333333> foo2(x = y/2, y = 10)5 10 On Wed, Mar 10, 2010 at 7:26 AM, Mark Heckmann <mark.heckmann at gmx.de> wrote:> 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 evaluated using > lazy loading. > > 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 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. >