# prints the currently displayed graph, on device number dvnum, to the
# file filename; dvnum will typically be 2; filename must be the name of
# a PDF file, quoted; it closes the PDF file and restores dvnum as the
# current device

prpdf <- function(dvnum, filename)  {
   pdf(filename)  # output from now on will go to the specified PDF file
   dvc <- dev.cur()  # determine our active display device
   dev.set(dvnum)  # set active device to the specified one
   dev.copy(which=dvc)  # copy
   dev.set(dvc)
   dev.off()
   dev.set(dvnum)
}
