我有一个制表符分隔的文本文件,想要使用read.table
函数将其加载到R中。脚本的前几行如下:
#!/usr/bin/env Rscript
args <- commandArgs(trailingOnly=TRUE)
data <- read.table(args[1], header=TRUE, sep="\t", quote="")
# process the data
这是可行的。我最初尝试让R从标准输入读取数据,但未成功。我的第一个尝试...
#!/usr/bin/env Rscript
data <- read.table(stdin(), header=TRUE, sep="\t", quote="")
# process the data
...似乎完全没有起作用。 我的第二种方法...
#!/usr/bin/env Rscript
data <- read.table("/dev/stdin", header=TRUE, sep="\t", quote="")
# process the data
我需要读取数据文件,但是(由于某些我不理解的原因),前20行左右会被破坏,这是一个大问题(特别是因为这些行包含头部信息)。有没有办法让read.table
从标准输入中读取?我是否漏掉了什么非常明显的东西?
read.table(file("stdin"))
仍然是个好用的技巧。 - Christopher Bottoms