Re: [R] Plotting with Statistics::R, Perl/R

2005-01-24 Thread Tim Churches
Peter Dalgaard wrote:
d) Use bitmap(). It requires a working Ghostscript install, but is
otherwise much more convenient. Newer versions of Ghostscript have
some quite decent antialiasing built into some of the png devices.
Currently you need a small hack to pass the extra options to
Ghostscript -- we should probably add a gsOptions argument in due
course. This works for me on FC3 (Ghostscript 7.07):
mybitmap(file=foo.png, type=png16m, gsOptions= -dTextAlphaBits=4
-dGraphicsAlphaBits=4 )
where mybitmap() is a modified bitmap() that just sticks the options
into the command line. There are definitely better ways...
[The antialiasing is not quite perfect. In particular, the axes stand
out from the box around plots, presumably because an additive model is
used (so that if you draw a line on top of itself, the result becomes
darker). Also, text gets a little muddy at the default 9pt @ 72dpi, so
you probably want to increase the pointsize or the resolution.]
 

Apart from the significant quality issues which you mention, the other 
problem with using bitmap() in a Web server environment is the speed 
issue - it takes much longer to produce the output. Whether it takes too 
long depends on the users of your Web application, and how many 
simultaneous users there are. However, most users are more worried by 
the poor quality of the fonts in output produced by bitmap().

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


Re: [R] Plotting with Statistics::R, Perl/R

2005-01-22 Thread Peter Dalgaard
Dirk Eddelbuettel [EMAIL PROTECTED] writes:

 a) if you must have png() as a format, you can start a virtual X11 server
with the xvfb server -- this is a bit involved, but doable;

 b) if you can do other formats instead of png(), this can work -- I have
forgotten the details but the story has been discussed many times over
here as web servers use the same session-less setup.  In essence,
using ghostscript for the bitmap conversion works so it may be that
the bitmap() device works.  If I recall pdf(), works.  

 c) With that, you could try creating a pdf() first, and then use Perl to
call ghostscript to convert the pdf for you.  R can do that too for
you, but only for certain devices.  

d) Use bitmap(). It requires a working Ghostscript install, but is
otherwise much more convenient. Newer versions of Ghostscript have
some quite decent antialiasing built into some of the png devices.
Currently you need a small hack to pass the extra options to
Ghostscript -- we should probably add a gsOptions argument in due
course. This works for me on FC3 (Ghostscript 7.07):

mybitmap(file=foo.png, type=png16m, gsOptions= -dTextAlphaBits=4
-dGraphicsAlphaBits=4 )

where mybitmap() is a modified bitmap() that just sticks the options
into the command line. There are definitely better ways...

[The antialiasing is not quite perfect. In particular, the axes stand
out from the box around plots, presumably because an additive model is
used (so that if you draw a line on top of itself, the result becomes
darker). Also, text gets a little muddy at the default 9pt @ 72dpi, so
you probably want to increase the pointsize or the resolution.]

-- 
   O__   Peter Dalgaard Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics 2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark  Ph: (+45) 35327918
~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907

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


[R] Plotting with Statistics::R, Perl/R

2005-01-21 Thread Leah Barrera
I am trying to plot in R from a perl script using the Statistics::R
package as my bridge.  The following are the conditions:

0. I am running from a Linux server.

1. Even without xwindows the following saves test.png correctly from an
interactive session with R:
 xy-cbind(1,1)
 png(test.png)
 plot(xy)
 dev.off()

2. However, when called from the perl script I get the ff. warning:
--
X11 module is not available under this GUI
--
and nothing is saved

3. I tried to hijack the script by modifying
lib/Statistics/R/Bridge/Linux.pm to remove the
gui=none setting
--
$this-{START_CMD} = $this-{R_BIN} --slave --vanilla --gui=none ;
--
changed to
--
$this-{START_CMD} = $this-{R_BIN} --slave --vanilla ;
--

4.  When plotting in R from the perl script again, I no longer get the
warning and  I get test.png saved, but it is empty.

Please advise.

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


Re: [R] Plotting with Statistics::R, Perl/R

2005-01-21 Thread Dirk Eddelbuettel
On Fri, Jan 21, 2005 at 06:06:45PM -0800, Leah Barrera wrote:
 I am trying to plot in R from a perl script using the Statistics::R
 package as my bridge.  The following are the conditions:
 
 0. I am running from a Linux server.
 
 1. Even without xwindows the following saves test.png correctly from an
 interactive session with R:
  xy-cbind(1,1)
  png(test.png)
  plot(xy)
  dev.off()
 
 2. However, when called from the perl script I get the ff. warning:
 --
 X11 module is not available under this GUI
 --
 and nothing is saved
 
 3. I tried to hijack the script by modifying
 lib/Statistics/R/Bridge/Linux.pm to remove the
 gui=none setting
 --
 $this-{START_CMD} = $this-{R_BIN} --slave --vanilla --gui=none ;
 --
 changed to
 --
 $this-{START_CMD} = $this-{R_BIN} --slave --vanilla ;
 --
 
 4.  When plotting in R from the perl script again, I no longer get the
 warning and  I get test.png saved, but it is empty.
 
 Please advise.

It's a FAQ.  

Plotting certain formats requires the X11 server to be present as the font
metrics for those formats can be supplied only the X11 server. Other drivers
don;t the font metrics from X11 -- I think pdf is a good counterexample.
When you run in 'batch' via a Perl script, you don't have the X11 server --
even though it may be on the machine and running, it is not associated with
the particular session running your Perl job.  There are two common fixes:

a) if you must have png() as a format, you can start a virtual X11 server
   with the xvfb server -- this is a bit involved, but doable;
   
b) if you can do other formats instead of png(), this can work -- I have
   forgotten the details but the story has been discussed many times over
   here as web servers use the same session-less setup.  In essence,
   using ghostscript for the bitmap conversion works so it may be that
   the bitmap() device works.  If I recall pdf(), works.  
   
c) With that, you could try creating a pdf() first, and then use Perl to
   call ghostscript to convert the pdf for you.  R can do that too for
   you, but only for certain devices.  
   
Hth,  Dirk   

-- 
Better to have an approximate answer to the right question than a precise 
answer to the wrong question.  --  John Tukey as quoted by John Chambers

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


Re: [R] Plotting with Statistics::R, Perl/R

2005-01-21 Thread Tim Churches
Dirk Eddelbuettel wrote:
Plotting certain formats requires the X11 server to be present as the font
metrics for those formats can be supplied only the X11 server. Other drivers
don;t the font metrics from X11 -- I think pdf is a good counterexample.
When you run in 'batch' via a Perl script, you don't have the X11 server --
even though it may be on the machine and running, it is not associated with
the particular session running your Perl job.  There are two common fixes:
a) if you must have png() as a format, you can start a virtual X11 server
  with the xvfb server -- this is a bit involved, but doable;
 

An example of a Python programme which manages the starting of an Xvfb 
server when one is required can be found in the xvfb_spawn.py file 
/SOOMv0 directory of the tarball for NetEpi Analysis, which can be 
downloaded by following the links at http://www.netepi.org

xvfb_spawn.py was written for use with RPy, which is a Python-to-R 
bridge, when used in a Web server setting (hence no X11 display server 
available). It should be possible to translate the programme to Perl, or 
to write somethig similar in Perl. Comments in the code note some 
potential security traps for the unwary.

Hopefully one day the dependency of the R raster graphics devices on an 
X11 server will be removed. R on Win32 doesn't have that dependency (but 
then, Windows machines, even servers, have displays running all the time 
as part of their kernel, and who would wish that on other operating 
system?). However, there are several graphics back-ends which produce 
very high quality raster graphics on POSIX platforms without the need 
for an X11 device to be present - Agg (Anti-grain geometry, see 
http://www.antigrain.com/) and Cairo (see http://cairographics.org/) 
spring to mind (usually disclaimers about the foregoing comments not 
meaning to seem like ingratitude to the R development team etc apply).

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


Re: [R] Plotting with Statistics::R, Perl/R

2005-01-21 Thread Joe Conway
Dirk Eddelbuettel wrote:
On Fri, Jan 21, 2005 at 06:06:45PM -0800, Leah Barrera wrote:
I am trying to plot in R from a perl script using the Statistics::R
 package as my bridge.  The following are the conditions:
0. I am running from a Linux server.
Plotting certain formats requires the X11 server to be present as the
font metrics for those formats can be supplied only the X11 server.
Other drivers don;t the font metrics from X11 -- I think pdf is a
good counterexample. When you run in 'batch' via a Perl script, you
don't have the X11 server -- even though it may be on the machine and
running, it is not associated with the particular session running
your Perl job.  There are two common fixes:
a) if you must have png() as a format, you can start a virtual X11
server with the xvfb server -- this is a bit involved, but doable;
Attached is an init script I use to start up xvfb on Linux.
HTH,
Joe
#!/bin/bash
#
# syslogStarts Xvfb.
#
#
# chkconfig: 2345 12 88
# description: Xvfb is a facility that applications requiring an X frame buffer 
\
# can use in place of actually running X on the server

# Source function library.
. /etc/init.d/functions

[ -f /usr/X11R6/bin/Xvfb ] || exit 0

XVFB=/usr/X11R6/bin/Xvfb :5 -screen 0 1024x768x16

RETVAL=0

umask 077

start() {
echo -n $Starting Xvfb: 
$XVFB
RETVAL=$?
echo_success
echo
[ $RETVAL = 0 ]  touch /var/lock/subsys/Xvfb
return $RETVAL
}
stop() {
echo -n $Shutting down Xvfb: 
killproc Xvfb
RETVAL=$?
echo
[ $RETVAL = 0 ]  rm -f /var/lock/subsys/Xvfb
return $RETVAL
}
restart() {
stop
start
}

case $1 in
  start)
start
;;
  stop)
stop
;;
  restart|reload)
restart
;;
  condrestart)
[ -f /var/lock/subsys/Xvfb ]  restart || :
;;
  *)
echo $Usage: $0 {start|stop|restart|condrestart}
exit 1
esac

exit $RETVAL

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

Re: [R] Plotting with Statistics::R, Perl/R

2005-01-21 Thread Tim Churches
Joe Conway wrote:
Dirk Eddelbuettel wrote:
On Fri, Jan 21, 2005 at 06:06:45PM -0800, Leah Barrera wrote:
I am trying to plot in R from a perl script using the Statistics::R
 package as my bridge.  The following are the conditions:
0. I am running from a Linux server.
Plotting certain formats requires the X11 server to be present as the
font metrics for those formats can be supplied only the X11 server.
Other drivers don;t the font metrics from X11 -- I think pdf is a
good counterexample. When you run in 'batch' via a Perl script, you
don't have the X11 server -- even though it may be on the machine and
running, it is not associated with the particular session running
your Perl job.  There are two common fixes:
a) if you must have png() as a format, you can start a virtual X11
server with the xvfb server -- this is a bit involved, but doable;

Attached is an init script I use to start up xvfb on Linux.
HTH,
Joe

#!/bin/bash
#
# syslogStarts Xvfb.
#
#
# chkconfig: 2345 12 88
# description: Xvfb is a facility that applications requiring an X frame buffer 
\
# can use in place of actually running X on the server
# Source function library.
. /etc/init.d/functions
[ -f /usr/X11R6/bin/Xvfb ] || exit 0
XVFB=/usr/X11R6/bin/Xvfb :5 -screen 0 1024x768x16
RETVAL=0
umask 077
start() {
   echo -n $Starting Xvfb: 
   $XVFB
   RETVAL=$?
   echo_success
   echo
   [ $RETVAL = 0 ]  touch /var/lock/subsys/Xvfb
   return $RETVAL
}
stop() {
   echo -n $Shutting down Xvfb: 
   killproc Xvfb
   RETVAL=$?
   echo
   [ $RETVAL = 0 ]  rm -f /var/lock/subsys/Xvfb
   return $RETVAL
}
restart() {
   stop
   start
}
case $1 in
 start)
   start
   ;;
 stop)
   stop
   ;;
 restart|reload)
   restart
   ;;
 condrestart)
   [ -f /var/lock/subsys/Xvfb ]  restart || :
   ;;
 *)
   echo $Usage: $0 {start|stop|restart|condrestart}
   exit 1
esac
exit $RETVAL
 

Hmm, the only problem with that is that, if I am not mistaken, you are 
starting Xvfb without any authentication, and I am told by people who 
know about such things that in the context of an Internet-accessible Web 
server, having an X server accepting unauthenticated connections is not 
a good idea. In other, less hostile environments, it might be OK. Maybe 
such concerns are unreasonable paranoia, but my motto is better safe 
than sorry when it comes to Internet-facing servers. I think there are 
also other switches you can pass to Xvfb to stop it listening on various 
TCP/IP ports etc.

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