Default arguments are evaluated in the function frame, not in the calling environment (nor in the same place as explicit arguments).
> Which to me reads that a with statement as above is equivalent to > > > attach(data) ; aov.SS1(y=Obs) ; detach(data) > > Or is that just wishful thinking?? The latter. On Thu, 7 Oct 2004, RenE J.V. Bertin wrote: > Hello, > > I'm having a little argument with the 'with' function. I have > > > aov.SS1 <- function( y, indep=speed, fSnr=Subject, ... ) > { > indep <- factor(speed) > fSnr <- factor(fSnr) > ## .... > } > > and a dataframe containing speed, Subject, and a bunch of other columns. If I now do > > > with( data, aov.SS1( y=Obs ) ) > > I get a message > > Error in factor(indep) : Object "speed" not found > > It seems that automatic argument initialisation doesn't work, as the only > effectively valid call seems to be > > > with( data, aov.SS1( y=Obs, indep=speed, fSnr=Subject ) ) > > whereas > > > with( data, speed ) > > prints what one would expect (i.e. data$speed). > > How come? From ?with, one learns that > "... assignments within 'expr' take place in the constructed > environment and not in the user's workspace." > > Which to me reads that a with statement as above is equivalent to > > > attach(data) ; aov.SS1(y=Obs) ; detach(data) > > Or is that just wishful thinking?? > > RenE > > ______________________________________________ > [EMAIL PROTECTED] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > > -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595 ______________________________________________ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html