R data.table从剪贴板中删除 [英] R data.table fread from clipboard

查看:309
本文介绍了R data.table从剪贴板中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个界面excel-R :: data.table。
我想问如何可能使用fread函数与剪贴板。
下面的代码运行良好,但我更喜欢使用fread而不是read.table(在excel文件中复制一些表,并在R中运行上面的命令):

  data.table(read.table(clipboard,sep =\t,header = TRUE))
pre>

我试着声明连接到剪贴板,但迄今为止不能得到它的工作。也正如fread函数文档中所述,它会改变,一些事情可能会被弃用,所以它可能是一个很好的解决方案,不会被废弃在不久的将来。
剪贴板/ fread有任何限制吗?像65000行或其他内存限制?



我还建议扩展data.table :: fread函数接受'剪贴板'连接默认为



感谢

解决方案

code> fread 似乎没有这个功能,但是对于有限的使用,你可以轻松地为它写自己的包装。下面几行可能会帮助你开始:

  freadClip<  -  function(...){
X< - tempfile()
writeLines(readLines(clipboard),X)
fread(X,...)
}

用法只是复制您的Excel表单中的单元格,切换回R,然后键入 freadClip code>。



注意:我假设这是一个更方便的功能,从Excel快速获取一个小数据集到R中。我不知道我是否会亲自为65k行范围内的文件使用clipboard您的问题。


I want to create an interface excel-R::data.table. I would like to ask how it is possible to use fread function with clipboard. Following code is working well but I would prefer to use fread instead of read.table (to reproduce copy some table in excel file and run above command in R):

data.table(read.table("clipboard",sep="\t",header=TRUE))

I tried declaring connection to clipboard but so far cannot get it work. Also as stated in fread function documentation it is going to change and some things might be deprecated so it could be nice to have a solution which is not going to be deprecated in close future. Is there any limits for clipboard/fread? like 65000 rows, or some other memory limit?

I also would like to suggest to extend data.table::fread function to accept 'clipboard' connect by default as it is works currently with read.table.

Thanks

解决方案

fread doesn't seem to have this feature, but for limited use, you can easily write your own wrapper for it. Something along the lines of the following might help you get started:

freadClip <- function(...) {
  X <- tempfile()
  writeLines(readLines("clipboard"), X)
  fread(X, ...)
}

Usage would just be copying the cells from your Excel sheet, switching back to R, and typing freadClip().

Note: I'm assuming that this is more of a convenience function than anything--mostly for quickly getting a small dataset from Excel into R. I don't know if I would personally use "clipboard" for a file in the range of 65k rows as you describe in your question.

这篇关于R data.table从剪贴板中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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