[R] Note: "The default device has been opened to honour attempt to modify trellis settings"

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Wed Mar 16 13:33:35 CET 2005



Luis Ridao Cruz wrote on 3/16/2005 5:16 AM:
> R-help,
> 
> I'm using a function whose end result is a trellis plot.
> When I call the function I get sometimes the following message:
> 
> "Note: The default device has been opened to honour attempt to modify
> trellis settings "
> 
> leading up to any plot whatsoever.
> 
> I call the package 'lattice' within the function and 'detach' after
> plotting.
> 
> I have to close the graphics device to get the desired result (and it
> works only after a few more function calls)
> 
> Here is the function code
> 
> "function"<-function(somedata)
> {
>  ..........
> 
> library(lattice)
> trellis.par.set(theme = col.whitebg())
> 
> xyplot(log.catch ~ age | yrclass , data = tmp2)
> 
> detach(package:lattice)
> 
> savePlot(file="catch curve",type="jpeg")
> 
> }
> 
> function(somedata)
> 
> 
> Thanks in advance.
> 
> I'm running on Windows XP
> 
> 
>>version
> 
>          _              
> platform i386-pc-mingw32
> arch     i386           
> os       mingw32        
> system   i386, mingw32  
> status                  
> major    2              
> minor    0.1            
> year     2004           
> month    11             
> day      15             
> language R
> 


Luis,

If you are trying to save a plot within a function, you are going about 
it the wrong way.

# don't call your function "function"
# "function"<-function(somedata)
my.function <- function(somedata) {
   require(lattice) # minor change here
   # next line is what's causing the message
   # trellis.par.set(theme = col.whitebg())
   trellis.device(jpeg, file = "catch_curve.jpg", theme = col.whitebg())
   # need to explicitly print the plot to the current device
   # see FAQ 7.22
   print(xyplot(log.catch ~ age | yrclass , data = tmp2))
   # turn device off after printing
   dev.off()
   # not sure why you need to detach every time ...
   detach(package:lattice)
   #savePlot(file="catch curve",type="jpeg")
}

my.function(somedata)

--sundar




More information about the R-help mailing list