Alex Pine
2008-Dec-29 19:57 UTC
[R] Is there some way to append to a pdf after its device has been closed?
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 haven't been able to figure out a way to do that. If one calls pdf(file="myfile"), and "myfile" already exists, it will be overwritten. Is there any way that I can make the pdf() function append to the existing file instead? And if not, is there any way to call a program like pdfmerge ( http://microtronyx.com/pdfmerge/ ) from inside R code? I know I could simply write to a different pdf file every time I would otherwise do an append and then merge those files once my R program has completed, but in my case that would lead to the creation of literally thousands of pdf files before I merged them all together, and I would like to avoid that if possible. Thank you for any help you can give, Alex [[alternative HTML version deleted]]
jim holtman
2008-Dec-29 20:27 UTC
[R] Is there some way to append to a pdf after its device has been closed?
Why don't you just output all the plot to a single file by opening 'pdf', doing the plots, 'dev.off()'. Why do you need so many files open? On Mon, Dec 29, 2008 at 2:57 PM, Alex Pine <alex.pine at nyu.edu> 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 haven't been able to figure out a way > to do that. If one calls pdf(file="myfile"), and "myfile" already exists, it > will be overwritten. Is there any way that I can make the pdf() function > append to the existing file instead? And if not, is there any way to call a > program like pdfmerge ( http://microtronyx.com/pdfmerge/ ) from inside R > code? I know I could simply write to a different pdf file every time I would > otherwise do an append and then merge those files once my R program has > completed, but in my case that would lead to the creation of literally > thousands of pdf files before I merged them all together, and I would like > to avoid that if possible. > > Thank you for any help you can give, > > Alex > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
Stephan Kolassa
2008-Dec-29 20:49 UTC
[R] Is there some way to append to a pdf after its device has been closed?
Hi Alex, you can have R execute OS commands using system(), perhaps you can call pdfmerge that way. Or (admittedly less elegantly), you can use LaTeX with the pdfpages package, either using Sweave or system(pdflatex ...). Good luck, Stephan Alex Pine schrieb:> 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 haven't been able to figure out a way > to do that. If one calls pdf(file="myfile"), and "myfile" already exists, it > will be overwritten. Is there any way that I can make the pdf() function > append to the existing file instead? And if not, is there any way to call a > program like pdfmerge ( http://microtronyx.com/pdfmerge/ ) from inside R > code? I know I could simply write to a different pdf file every time I would > otherwise do an append and then merge those files once my R program has > completed, but in my case that would lead to the creation of literally > thousands of pdf files before I merged them all together, and I would like > to avoid that if possible. > > Thank you for any help you can give, > > Alex > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org 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. >
Patrick Connolly
2008-Dec-30 05:49 UTC
[R] Is there some way to append to a pdf after its device has been closed?
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 ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.