RE: [R] Decreasing my personal entropy ...

2003-01-31 Thread Warnes, Gregory R
Lattice plots and trellice plots are actually displayed by thier 'print'
methods.  So, to get ta plot to be displayed in a non-interactive context,
such as a script, explicitly call print on the results of the plot command.

-Greg

-Original Message-
From: Gunter, Bert
To: R-Help (E-mail)
Sent: 1/31/03 8:45 AM
Subject: [R] Decreasing my personal entropy ...

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.
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?  

Many thanks.

Bert Gunter
Biometrics Research RY 84-16
Merck & Company
P.O. Box 2000
Rahway, NJ 07065-0900
Phone: (732) 594-7765
mailto: [EMAIL PROTECTED]

"The business of the statistician is to catalyze the scientific learning
process."  -- George E.P. Box



--

__
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help


LEGAL NOTICE\ Unless expressly stated otherwise, this message is ... [[dropped]]

__
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help



Re: [R] Decreasing my personal entropy ...

2003-01-31 Thread Douglas Bates
"Gunter, Bert" <[EMAIL PROTECTED]> 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[EMAIL PROTECTED]
Statistics Department608/262-2598
University of Wisconsin - Madisonhttp://www.stat.wisc.edu/~bates/

__
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help



Re: [R] Decreasing my personal entropy ...

2003-01-31 Thread John Fox
Dear Bert,

At 08:45 AM 1/31/2003 -0500, Gunter, Bert wrote:

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.
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?


Actually, a function that calls xyplot() won't necessarily produce a plot 
without an explicit call to print(). Consider the following two functions:

fun.1 <- function(x,y) {xyplot(y~x); return(NULL)}
fun.2 <- function(x,y) xyplot(y~x)

fun.1 doesn't plot anything; fun.2 produces a plot when called from the 
command prompt, but only when its result is unassigned, and only because it 
returns an object of class "trellis", which is then automatically printed.

The general point is that the print method for trellis objects plots the 
objects, so when print() gets called implicitly on a trellis object, the 
object is plotted.

I hope that this helps,
 John
-
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada L8S 4M4
email: [EMAIL PROTECTED]
phone: 905-525-9140x23604
web: www.socsci.mcmaster.ca/jfox
-

__
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help