[R] 'with' usage question
Prof Brian Ripley
ripley at stats.ox.ac.uk
Thu Oct 7 19:02:26 CEST 2004
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
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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, ripley at stats.ox.ac.uk
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
More information about the R-help
mailing list