Skip to content
Prev 44188 / 398503 Next

calling R from a shell script and have it display graphics

Christophe Pallier <pallier at lscp.ehess.fr> wrote:
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);