R: Function to copy to clipboard on Mac/OSX? [duplicate]

末鹿安然 提交于 2019-11-30 06:45:21

问题


I've seen a Windows function to copy to the clipboard in R. Is there an equivalent function for Mac OSX?


回答1:


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.




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/9035674/r-function-to-copy-to-clipboard-on-mac-osx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!