[R] Problem calling xyplot() within a function
    Sundar Dorai-Raj 
    sundar.dorai-raj at pdf.com
       
    Fri Apr 28 05:24:47 CEST 2006
    
    
  
Steve Candy wrote:
> Hi All
>  
> I'm fairly new at R so there might be on obvious solution to my problem
> with calling the lattice function xyplot( ) from my own function.
>  
> The function script is given below.
>  
> The problem is that the xyplot() call does not do anything! I just get a
> blank graphics window and no error messages.
>  
> The simple plot() function call works fine when not commented out so I
> know the data is getting in OK and when I run the the same xyplot()
> function call outside this function substituting the actual data frame
> then xyplot( ) works fine. Comparing the data summary both inside and
> outside the function showed that the data is identical. I put the
> "require('lattice')" statement in because I thought it might help but it
> did'nt. 
>  
> Any help as to why xyplot() is behaving differently to plot() and what I
> need to do to get the function working would be much appreciated.
>  
<example snipped>
This is FAQ 7.22.
http://cran.r-project.org/doc/FAQ/R-FAQ.html
7.22 Why do lattice/trellis graphics not work?
The most likely reason is that you forgot to tell R to display the 
graph. Lattice functions such as xyplot() create a graph object, but do 
not display it (the same is true of Trellis graphics in S-Plus). The 
print() method for the graph object produces the actual display. When 
you use these functions interactively at the command line, the result is 
automatically printed, but in source() or inside your own functions you 
will need an explicit print() statement.
--sundar
    
    
More information about the R-help
mailing list