[R] Copying from graphics window in OS X
Don MacQueen
macq at llnl.gov
Fri Sep 16 16:33:30 CEST 2005
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
> pl.copy
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)
}
> pl.email
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:
>I hope there is a way...at the moment an os X screen grab is the only
>way to get a quick copy. When I ran Cygwin on a PC, copying from graphic
>windows was as easy as ctrl+c--so it doesn't sound like an X11
>limitation. I'd like to know what Cygwin was doing in the background...
>
>Sean Davis wrote:
>
>>On 9/15/05 3:14 PM, "Chris Wiita" <cgwiita at ucla.edu> wrote:
>>
>>
>>
>>>I'm running R from an Xterm window is OSX-Tiger. Graphical windows
>>>appear as they should, but I'm having trouble copying from them--using
>>>cmd+c or the Copy option in the Edit menu won't place the graph in the
>>>clipboard (when I paste into a running OS X app, I get whatever was the
>>>last copied thing from a non-x11 window). Any ideas on how to copy from
>>>a xterm-launched graphical window? I can copy/paste into and out of the
>>>xterm command line, but I can't get anything from a graphical window.
>>>
>>>
>>
>>I don't think it is possible, but I would love to be corrected. You can
>>simple make a png, pdf, etc. if you want to save the graphic.
>>
>>Sean
>>
>>
>>
>>
>
>______________________________________________
>R-help at 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
--
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
More information about the R-help
mailing list