From: Jason Q. McClintic <jqmcclintic_at_stthomas.edu>

Date: Mon, 24 Mar 2008 21:34:14 -0500

Date: Mon, 24 Mar 2008 21:34:14 -0500

Suppose I have functions foo1, foo2, and foo3 such that:

foo1<-function(a=1,b=TRUE,c=FALSE){#do stuff}; foo2<-function(x=1,y=FALSE,z=c(1,2,3,4)){#do stuff}; foo3<-function(lambda,...){lambda*foo1()*foo2()};

To get a better feel for things I've been playing with examples such as:

b<-c(0.25,0.25); fun<-function(a=1,...){a*b};

fun() returns 0.25 0.25 as expected.

fun(a=2) returns 0.5 0.5 as expected.

However, fun(b=1) returns 0.25 0.25 when I want to overwrite b with the
value 1 and have it return 1.

Likewise with

fun<-function(a=1,...){a*return(b)};

any argument I supply for b seems to be ignored.

I understand as b is not defined within the function when I enter

fun()

lexical scoping means R looks for b up one level and, finding b, uses it.

Thanks for any/all help.

Sincerely,

Jason Q. McClintic

-- Jason Q McClintic UST MB 1945 2115 Summit Avenue St. Paul, MN 55105 jqmcclintic_at_stthomas.edu mccl0219_at_tc.umn.edu "It is insufficient to protect ourselves with laws, we must protect ourselves with mathematics."--Bruce Schneier ______________________________________________ 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.Received on Tue 25 Mar 2008 - 03:27:20 GMT

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.2.0, at Tue 25 Mar 2008 - 11:30:24 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*