Re: [R] plot via xyplot not being saved

From: Benilton Carvalho <bcarvalh_at_jhsph.edu>
Date: Sat, 16 Jun 2007 00:55:56 -0400

Thank you Deepayan,

I understand the behavior of not printing out the results inside the functions.

What I didn't know was that for xyplot() saving the plot actually meant "save the result I see", which does not happen with plot(), in which case my function test() works just fine if I replaced xyplot() by plot().

Thank you very much,

b

On Jun 16, 2007, at 12:26 AM, deepayan.sarkar_at_gmail.com wrote:

> On 6/15/07, Benilton Carvalho <bcarvalh@jhsph.edu> wrote:
>> So, if those statements are inside a function, I have to make my
>> function to have an 'echo' argument/functionality? eg.:
>>
>> ## begin test.R
>> test <- function(n){
>> y <- rnorm(n)
>> x <- rnorm(n)
>> z <- sample(letters[1:4], n, rep=T)
>> library(lattice)
>> bitmap("tst.png")
>> xyplot(y~x|z)
>> dev.off()
>> }
>>
>> test(100)
>> ## end test.R
>>
>> source("test.R", echo=T)
>>
>> also fails in this case...
>
> Yes. The following will produce some output (the values of x + y and x
> - y) if you type it out at the R prompt:
>
> x <- rnorm(10)
> y <- rnorm(10)
> x + y
> x - y
>
> If you put that in a file and source it, nothing will get printed,
> unless you have echo=TRUE. If you define
>
> test <- function(){
> x <- rnorm(10)
> y <- rnorm(10)
> x + y
> x - y
> }
>
> calling test() at the R prompt will only print x - y and not x + y,
> and so on.
>
> This is all standard R behaviour. If you want something to be printed
> irrespective of context, use print(), e.g.
>
> print(x + y)
>
> or
>
> print(xyplot(y~x|z))
>
> This is also mentioned in the R FAQ.
>
> -Deepayan



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 and provide commented, minimal, self-contained, reproducible code. Received on Sat 16 Jun 2007 - 05:08:54 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 16 Jun 2007 - 07:31:58 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.