On 10/12/2009 08:30 PM, Deepayan Sarkar wrote:
On Mon, Oct 12, 2009 at 9:32 AM, Jacob Wegelin<jacob.wege...@gmail.com>  wrote:
When we call a lattice function such as xyplot, to what extent does
the "data" designation cause the function to look inside the "data"
for variables?

In the examples below, the "subset" argument understands that
"Variety" is a variable in the data.

But the "scales" argument does not understand that "nitro" is a
variable in the data.

What principle is at work?

A strange one called "standard non-standard evaluation"; see

http://developer.r-project.org/nonstandard-eval.pdf

for a nice overview by Thomas Lumley.


?xyplot says:

     data: For the ‘formula’ method, a data frame containing values (or
           more precisely, anything that is a valid ‘envir’ argument in
           ‘eval’, e.g. a list or an environment) for any variables in
           the formula, as well as ‘groups’ and ‘subset’ if applicable.
           If not found in ‘data’, or if ‘data’ is unspecified, the
           variables are looked for in the environment of the formula.
           For other methods (where ‘x’ is not a formula), ‘data’ is
           usually ignored, often with a warning.

so the non-standard evaluation only applies to 'groups' and 'subset'.
The list may be different for other functions, e.g., densityplot()
also evaluates 'weights' in 'data'.

-Deepayan

In addition, you might want to use with, as in:

with( Oats, xyplot(
yield ~ nitro,scales=list(x=list(at=unique(nitro))), subset=Variety=="Victory"
) )

Romain

--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/BcPw : celebrating R commit #50000
|- http://tr.im/ztCu : RGG #158:161: examples of package IDPmisc
`- http://tr.im/yw8E : New R package : sos

______________________________________________
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