如何在Mac上从R写入剪贴板 [英] How to write from R to the clipboard on a mac

查看:110
本文介绍了如何在Mac上从R写入剪贴板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用write.table函数在Mac OS系统上写入剪贴板。在其他线程中,我尝试过

I am trying to use the write.table function to write to my clipboard on a mac os system. From other threads, I've tried

data <- rbind(c(1,1,2,3), c(1,1, 3, 4), c(1,4,6,7))
clip <- pipe("pbcopy", "w")                       
write.table(data, file="clip")                               
close(clip)

此代码未给出任何错误消息,但也不会将任何内容复制到剪贴板。
有什么建议吗?

This code does not give any error messages, but also does not copy anything to the clipboard. any suggestions?

推荐答案

在OS X下我没有任何机器可以测试它,但是我想您应该只使用 clip 而不是 clip

I don't have any machine under OS X to test it, but I think you should use just clip instead of "clip":

data <- rbind(c(1,1,2,3), c(1,1, 3, 4), c(1,4,6,7))
clip <- pipe("pbcopy", "w")                       
write.table(data, file=clip)                               
close(clip)

此处 clip 是R对象。

如果将字符串 clip传递给 file 参数R会认为它是文件名,并且而不是在剪贴板中查找数据,您将在R会话工作目录中找到一个名为 clip的文件,其中包含您的数据。

If you pass a string "clip" to the file argument R will think it is a file name, and instead of finding your data in clipboard, you will find a file in you R session working directory called "clip" with your data inside.

这篇关于如何在Mac上从R写入剪贴板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆