[R] Unattended printing under Windows

Michael Camann mac24 at humboldt.edu
Tue Feb 27 23:50:55 CET 2001


> R-help list--
> 
> I need to process a BUNCH of data in a very repetitious way (literally
> days of running the same simple analyses and producing summary graphics
> over and over).  I can't face the mind-numbing boredom of this task!


Thanks to all who responded.  I thought I'd post the solution that
(mostly) worked in case others need it.  I used sink() to trap the text
output of multiple ecological assemblage organization analyses into
individual files with sequential numbers paste()'d into the file names to
make them unique.  Nothing new here.  I haven't printed them all yet, but
that should be trivial.

The tough part was printing the graphical output of each analysis on the
fly without being present to click the mouse.  I also needed to save the
graphics for later re-use, so I used win.metafile() to save them to .emf
files whose names corresponded with the text output files.  Unfortunately,
the corresponding print command win.print() simply feeds images to the
windows print system, opening a dialog box on my system.  DOES ANYONE KNOW
HOW TO TURN OFF THIS ANNOYING WINDOWS BEHAVIOR?  The moral is that *every*
action should have a command line alternative.  OK, end of rant.  The
windows default behavior might still work in some situations because any
*subsequent* images print automatically after the first dialog box is
clicked, until the next call to dev.off().  In other words, you can do:

plot (something)
win.print()               # click OK to close the dialog box and print

plot (something.else)     # it prints
plot (something.else)     # and so on, without further dialog boxes...

dev.off()                 # resets default behavior

Unfortunately, this strategy would not work for my needs. Instead, I used
postscript() and gsprint for Windows.  The resultant quality was not quite
as good as printing directly to the windows driver without the
intermediary postscript layer, but it was good enough.  For each analysis,
I used:

postscript(file="a_unique_filename", width=7, height=7, family="Times"
    print.it=TRUE, command="c:/Ghostgum/gsview/gsprint")
par(set.plot.parameters)
plot(something)
dev.off()

This is esentially identical to the unix solution, differing only in the
need to call gsprint rather then lpr.  It's possible that a similar
solution exists for the text pages using system() calls to the DOS port of
a2ps and then gsprint (I'm having trouble finding the a2ps port, however).

It took most of a day to write and debug the analysis routines and the
meta-function that orchestrated everything, but that was FAR more
interesting than the several days I anticipated running all the analyses
manually and doing all the mouse clicking to produce the printed output. 
The automated analyses actually finished in a couple of hours-- 200
separate analysis runs producing 200 printed plots and 200 text pages,
with speed limited primarily by the print spooler, I assume.

Thanks once again to the R development team for a superb tool, and to
those who responded with specific suggestions for solutions.

--Mike C.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Michael A. Camann                                  Voice: 707-826-3676
Assistant Professor of Zoology                       Fax: 707-826-3201
Institute for Forest Canopy Research     Email: mac24 at axe.humboldt.edu
Department of Biology                            ifcr at axe.humboldt.edu
Humboldt State University           
Arcata, CA 95521

                 URL:http://www.humboldt.edu/~mac24/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list