Re: [R] calling R from a shell script and have it display graphics

2004-02-13 Thread Michael A. Miller
 Don == Don MacQueen [EMAIL PROTECTED] 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([retps] )
  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)
}

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] calling R from a shell script and have it display graphics

2004-02-13 Thread David Brahm
Christophe Pallier [EMAIL PROTECTED] wrote:
 I would like to call R from a shell script and have it display a series 
 of graphics.
 The graphics should remain visible until the user clicks or presses a key.

One trick is to use locator(1), which waits for a mouse click on a plot.
Here's a minimal Perl script that runs R, displays a plot, and exits when the
click is detected.


eval 'exec /usr/local/bin/perl -s -S $0 $@'
  if 0;
open(SCRIPT, | R --vanilla --slave);
print SCRIPT 'EOF';

x11(width=5, height=3.5)
plot(1:10, 1:10)
z - locator(1)
q()

EOF
close(SCRIPT);

-- 
  -- David Brahm ([EMAIL PROTECTED])

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] calling R from a shell script and have it display graphics

2004-02-12 Thread Christophe Pallier
Hello,

I am running R under Linux/x11.

I would like to call R from a shell script and have it display a series 
of graphics.
The graphics should remain visible until the user clicks or presses a key.

I first tried R BATCH, but it does not load the x11 module, making it 
impossible to open x11 or png devices.

Then, I tried to call R with a 'here' script:

R --vanilla --quiet --args text.txt 'EOF'
file=commandArgs()[5]
cat('processing ',file,'\n')
...
x11()
plot(f2,log='xy',type='b',las=1,cex=.5,xlab='rang',ylab='freq')
Sys.sleep(10)
q()
EOF
The problem with this approach is that the script cannot interact with 
the user.
par(ask=T) will fail because it reads input from the script rather than 
from the keyboard.

While I am writing this, a solution comes to my mind: I could save all 
the graphics in png format (using R script.R), and when it is finished, 
call ImageMagick's display to show all the png (or use any other 
diaporama system). However, I find it a dirty hack.

Is there a simpler and cleaner way to achieve this?

Christophe Pallier
www.pallier.org
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] calling R from a shell script and have it display graphics

2004-02-12 Thread Don MacQueen
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.

-Don

At 11:57 AM +0100 2/12/04, Christophe Pallier wrote:
Hello,

I am running R under Linux/x11.

I would like to call R from a shell script and have it display a 
series of graphics.
The graphics should remain visible until the user clicks or presses a key.

I first tried R BATCH, but it does not load the x11 module, making 
it impossible to open x11 or png devices.

Then, I tried to call R with a 'here' script:

R --vanilla --quiet --args text.txt 'EOF'
file=commandArgs()[5]
cat('processing ',file,'\n')
...
x11()
plot(f2,log='xy',type='b',las=1,cex=.5,xlab='rang',ylab='freq')
Sys.sleep(10)
q()
EOF
The problem with this approach is that the script cannot interact 
with the user.
par(ask=T) will fail because it reads input from the script rather 
than from the keyboard.

While I am writing this, a solution comes to my mind: I could save 
all the graphics in png format (using R script.R), and when it is 
finished, call ImageMagick's display to show all the png (or use any 
other diaporama system). However, I find it a dirty hack.

Is there a simpler and cleaner way to achieve this?

Christophe Pallier
www.pallier.org
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


--
--
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] calling R from a shell script and have it display graphics

2004-02-12 Thread Seth Falcon
How about saving to png and writing a small html file and then launching
a browser?



On Thu, Feb 12, 2004 at 07:45:42AM -0800, Don MacQueen wrote:
 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.
 
 -Don
 
 
 At 11:57 AM +0100 2/12/04, Christophe Pallier wrote:
 Hello,
 
 I am running R under Linux/x11.
 
 I would like to call R from a shell script and have it display a 
 series of graphics.
 The graphics should remain visible until the user clicks or presses a key.
 
 I first tried R BATCH, but it does not load the x11 module, making 
 it impossible to open x11 or png devices.
 
 Then, I tried to call R with a 'here' script:
 
 R --vanilla --quiet --args text.txt 'EOF'
 file=commandArgs()[5]
 cat('processing ',file,'\n')
 ...
 x11()
 plot(f2,log='xy',type='b',las=1,cex=.5,xlab='rang',ylab='freq')
 Sys.sleep(10)
 q()
 EOF
 
 The problem with this approach is that the script cannot interact 
 with the user.
 par(ask=T) will fail because it reads input from the script rather 
 than from the keyboard.
 
 While I am writing this, a solution comes to my mind: I could save 
 all the graphics in png format (using R script.R), and when it is 
 finished, call ImageMagick's display to show all the png (or use any 
 other diaporama system). However, I find it a dirty hack.
 
 Is there a simpler and cleaner way to achieve this?
 
 Christophe Pallier
 www.pallier.org
 
 __
 [EMAIL PROTECTED] mailing list
 https://www.stat.math.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! 
 http://www.R-project.org/posting-guide.html
 
 
 -- 
 --
 Don MacQueen
 Environmental Protection Department
 Lawrence Livermore National Laboratory
 Livermore, CA, USA
 
 __
 [EMAIL PROTECTED] mailing list
 https://www.stat.math.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! 
 http://www.R-project.org/posting-guide.html

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html