I've seen a Windows function to copy to the clipboard in R
. Is there an equivalent function for Mac OSX?
From the help file for base::connections
:
Mac OS X users can use pipe("pbpaste") and pipe("pbcopy", "w") to read from and write to that system's clipboard.
Yep. Carl is exactly right. The best way is to use pbpaste/pbcopy.
Here's a good article on the details: http://langui.sh/2010/11/14/pbpaste-pbcopy-in-mac-os-x-or-terminal-clipboard-fun/
Rob
10/17/2013 - Update: As of R 3.0 the kmisc package contains the read.cb() function for multi-platform clipboard usage. Referenced from @agstudy's answer here: https://stackoverflow.com/a/14547293/168689
For generic clipboard-reading in Mac, the syntax would be:
indat<-scan(pipe("pbpaste"),what=character(),...)
The ...
here is just a place-holder, look up the scan
help to see the very many options you have (the scan
default is to expect a double
variable in the what
argument; character
is probably safest for generic copy, or you can choose whatever is right for your case).
Similarly, for pasting into the Mac clipboard, the generic Mac syntax is
outdat<-"Hi There!"
cat(outdat, file=pipe("pbcopy","w"), ...)
Note that the nearly the same syntax should work in Windows and Linux as well; you should just replace the pipe
calls with the generic connection name "clipboard"
.
The Kmisc package function mentioned above only works for data frames and tabular data, not for generic copy/paste.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With