[R] Is there some way to append to a pdf after its device has been closed?

Patrick Connolly p_connolly at slingshot.co.nz
Thu Jan 1 10:47:14 CET 2009


On Tue, 30-Dec-2008 at 11:21AM -0500, Alex Pine wrote:

|> Patrick,
|> 
|> The reason I'm having a problem is because R only allows a maximum of 64
|> devices to be open at one time. If it allowed more than that, I wouldn't
|> have a problem. One way to get around that problem would be if I could close
|> a device and then append to it later, but there doesn't seem to be a way to
|> do that. My code works something like the following:
|> 
|> iters <- 1:100
|> obj.list <- ( long list of complex objects, of which there are > 64 )
|> device.list <- (holds a reference to all postscript devices, one for each
|> object in obj.list)
|> 
|> for ( i in iters ) {
|>    for( j in length(obj.list) ) {
|>       dev.set( device.list( j ) )
|>       # do plotting and other stuff for this list member to the j-th file,
|> appending to what has
|>       # been plotted before now
|>    }
|> }
|> # close all devices


You haven't explained why you need all the devices.  What's wrong with
something very simple like this:

postscript(file = "GreatBigFile.ps")

# do plotting and other stuff in as many loops as you like

dev.off()

Then you'll have all your plots in GreatBigFile.ps

Maybe there's something about what you're doing that makes that no
use, but I can't guess what it is.  You'll have to tell me.



|> 
|> This code fails because I cannot have more than 64 devices at a time. If it
|> were possible, every time the inner loop is executed, to set the current
|> device to the one corresponding to that list member, append to the (possibly
|> non-empty) postscript file and then close the device at the end of the inner
|> loop, my problem would be solved. Can you figure out a way to do this?
|> 
|> Thanks,
|> 
|> Alex
|> 
|> On Tue, Dec 30, 2008 at 12:49 AM, Patrick Connolly <
|> p_connolly at slingshot.co.nz> wrote:
|> 
|> > On Mon, 29-Dec-2008 at 02:57PM -0500, Alex Pine wrote:
|> >
|> > |> Hello all,
|> > |>
|> >
|> > |> My question has to do with writing to pdf/ps files. Currently, my R
|> > |> program requires 100+ pdf devices to be open, which is over the
|> > |> limit of 64 devices that can be open at the same time, causing R to
|> > |> throw an exception. My problem could be solved if I could append to
|> > |> a pdf file after its initial device has been closed, but so far I
|> >
|> > If you told us why you've closed the device, we'd understand what your
|> > problem is.  Why can't you keep the same device open and as many pages
|> > as you like will be appended before you do the dev.off() thing?  You
|> > can change par settings for the individual pages if necessary.
|> >
|> > [...]
|> >
|> > HTH
|> > --
|> > ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
|> >    ___    Patrick Connolly
|> >  {~._.~}                         Great minds discuss ideas
|> >  _( Y )_                        Middle minds discuss events
|> > (:_~*~_:)                        Small minds discuss people
|> >  (_)-(_)                                   ..... Anon
|> >
|> > ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
|> >

-- 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.   
   ___    Patrick Connolly   
 {~._.~}                   Great minds discuss ideas    
 _( Y )_  	         Average minds discuss events 
(:_~*~_:)                  Small minds discuss people  
 (_)-(_)  	                      ..... Eleanor Roosevelt
	  
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.




More information about the R-help mailing list