Skip to content
Back to formatted view

Raw Message

Message-ID: <87u11vp2bm.fsf@lumen.indyrad.iupui.edu>
Date: 2004-02-13T12:54:21Z
From: Michael A. Miller
Subject: calling R from a shell script and have it display graphics
In-Reply-To: <p06002001bc514f2c36e7@[128.115.153.6]> (Don MacQueen's message of "Thu, 12 Feb 2004 07:45:42 -0800")

>>>>> "Don" == Don MacQueen <macq at llnl.gov> writes:

    > I don't know about the "simpler" part, but you could use
    > the tcltk package to put up a window that prompts the user
    > to continue.

Here's a function that does that.  I use to prompt the user to
choose among printing the current device with dev.print, saving
it with dev.copy2eps or continuing without doing anything.  I
write my codes to use this function and then, depending on
whether or not the code is running from a script or not, I
redefine it with the tk version.

Mike

##===================================================================================
## give the user some options at the command prompt
print.or.not <- function() {
  print("<return> to continue, `p' to print, `s' to save to R.ps...")
  result <- readline("[<ret>ps] ")
  if ( result == "p" ) { dev.print() }
  if ( result == "s" ) { dev.copy2eps(file="R.ps") }
}

##===================================================================================
## give the user some options in a tk window...
print.or.not <- function() {
  tt.print <- tktoplevel()
  tktitle(tt.print) <- 'Print or save plot?'
  b.print <- tkbutton(tt.print,
                      text='print',
                      command=function(...){ dev.print()
                                             tkdestroy(tt.print)
                                           }
                      )
  b.save <- tkbutton(tt.print,
                     text='save',
                     command=function(...){ file.obj <- tkgetSaveFile()
                                            file.name <- tclvalue(file.obj)
                                            dev.copy2eps(file=file.name)
                                            tkdestroy(tt.print)
                                          }
                     )
  b.continue <- tkbutton(tt.print,
                         text='continue',
                         command=function(...){ tkdestroy(tt.print)
                                              }
                         )
  tkpack(b.print, b.save, b.continue,fill='both')
  tkwait.window(tt.print)
}