[R] Decreasing my personal entropy ...
Douglas Bates
bates at stat.wisc.edu
Fri Jan 31 15:33:02 CET 2003
"Gunter, Bert" <bert_gunter at merck.com> writes:
> R-Listers:
>
> A very minor -- and maybe silly -- question just for personal enlightenment.
>
> In S (either R or S-Plus, AFAIK) when one types or pastes a trellis graphics
> command into the commands/console window, the graph is automatically
> produced:
> e.g.,
>
> trellis.device(...)
> xyplot(y~x)
>
> If one puts these in a function and calls the function, the same occurs.
Only if the trellis/lattice function call is the last function call in
your function.
> However, if one sources in these command from a file (i.e., using source()),
> automatic printing does not occur; one must explicitly call
> print(xyplot(y~x)) . Why do things work this way?
Trellis/lattice calls return objects. Plots are produced by the print
method for such objects. When used interactively R is in a
read-eval-print loop so the value of, for example,
> xyplot(y ~ x | f, data = mydata)
is equivalent to
> print(eval(parse(text="xyplot(y ~ x | f, data = mydata)")))
If you have a function that ends in a call to xyplot then the value of
the function is the value of the call to xyplot and it is treated the
same.
The reason that calls to source behave differently is described in the
R FAQ entry "Why is the output not printed when I source() a file?"
> Many thanks.
You're welcome. Regards from Madison.
--
Douglas Bates bates at stat.wisc.edu
Statistics Department 608/262-2598
University of Wisconsin - Madison http://www.stat.wisc.edu/~bates/
More information about the R-help
mailing list