[R] viewing Postscript file

Marc Schwartz MSchwartz at MedAnalytics.com
Fri Jul 23 01:44:02 CEST 2004


On Thu, 2004-07-22 at 16:50, Bickel, David wrote:
> Is there any R function that can display a Postscript file that is
> already in the working directory? For example, if 'graph.ps' is such a
> file, I'd like to type something like this:
> > plot.postscript.file(file = 'graph.ps')
> 
> If no such function exists, I'd be interested in a way to use existing
> R functions to do this under UNIX or Windows, preferably without a
> system call to GhostView (gv).
> 
> Thanks,
> David


I am not entirely sure what your expectations are here.

As you probably know, Postscript files (like PDF files) are text files
that describe how to draw an image. It requires a Postscript interpreter
(typically Ghostscript) to read the contents of the PS file and then
something like GSview (or gv or ggv or ...) as a front end to render the
image.

It is illusory, but you could create a R wrapper function and call it
plot.postcript.file():

plot.postscript.file <- function(file = "Rplots.ps")
{
  # define viewer for UNIX/LINUX or Windows
  viewer <- ifelse(.Platform$OS.type == "unix", "gv", "GSview")
   
  system(paste(viewer, file, sep = " "))
}


So:

postscript("graph.ps")
barplot(1:5)
dev.off()
plot.postscript.file("graph.ps")

HTH,

Marc Schwartz




More information about the R-help mailing list