Skip to content
Prev 77342 / 398502 Next

Copying from graphics window in OS X

It does look like a Cygwin feature. Possibly, another window manager, 
not Apple's XQuartz, would have something.

You could try xwd, which is available in the usual place, /usr/X11R6/bin.

I have written a couple of helper functions that might make things a 
little less painful if you don't find a satisfactory 
capture-to-clipboard solution.

Use them something like this:
    x11()            ## open a graphics window
    plot(....)        ## make a plot
    pl.copy()       ## copy it to a pdf (pdf is the default)
    pl.email()      ## email it to someone (default recipient is me)

    pl.copy() copies the current graph to a pdf, png, jpeg, eps, or ps file.
    pl.email(), called immediately after pl.copy(), will email that file.

pl.email() assumes that outgoing email can be sent using the 'mail' 
or 'mailx' command, so
you might to modify pl.email() for your linux server. It also assumes 
uuencode is available.

-Don
function (file = "currentgraph", gtype = c("pdf", "png", "jpeg", "eps",
     "ps"), width = 9, height = 5, wpixels = 700, hpixels = 400,
     time = FALSE, horizontal = FALSE, enc.for.ps = "ISOLatin1",
     enc.for.pdf = "AdobeStd", ...)
{
     gtype <- match.arg(gtype)
     file <- paste(file, if (time)
         format(Sys.time(), "-%Y-%m-%d-%H-%M")
     else "", ".", gtype, sep = "")
     gr <- recordPlot()
     switch(gtype, pdf = {
         pdf(file, width = width, height = height, onefile = FALSE,
             encoding = enc.for.pdf, ...)
     }, png = {
         png(file, width = wpixels, height = hpixels, ...)
     }, jpeg = {
         jpeg(file, width = wpixels, height = hpixels, ...)
     }, eps = {
         postscript(file, width = width, height = height, horizontal = 
horizontal,
             onefile = FALSE, paper = "special", encoding = enc.for.ps,
             ...)
     }, ps = {
         postscript(file, width = width, height = height, horizontal = 
horizontal,
             onefile = FALSE, paper = "special", encoding = enc.for.ps,
             ...)
     }, stop("invalid gtype\n"))
     replayPlot(gr)
     dev.off()
     assign("current.file", file, pos = ".GlobalEnv")
     cat("file is ", file, "\nfile name is stored in object \"current.file\"\n",
         sep = "")
     invisible(gr)
}
function (to = "macq at llnl.gov", file = current.file, from = Sys.getenv("USER"),
     subject = paste("Graph from", from), note = "", mail.cmd = {
         if (Sys.info()["sysname"] == "SunOS")
             "mailx"
         else "mail"
     })
{
     cmd <- paste("uuencode ", file, " ", file, " | ", mail.cmd,
         " -s \"", subject, "\" ", to, sep = "")
     cat("mailing with command:\n", cmd, "\n")
     system(cmd)
}
At 12:49 PM -0700 9/15/05, Chris Wiita wrote: