错误R csv:read.table出错(file = file,header = header,sep = sep,quote = quote,:'file'必须是字符串或连接

时间:2016-11-27 16:33:27

标签: r csv

我正在努力使用MiRLAB软件包的R教程,虽然我不确定问题是否与软件包的功能有关。

我想使用仅接受.csv文件的函数Pearson()。我已经完美地加载了一个文件,但是当我尝试了函数Pearson()时(MI,IDA和Lasso也是如此),出现了以下错误信息:

  

read.table出错(file = file,header = header,sep = sep,quote =   引用,:'file'必须是字符串或连接

dataset=read.csv("ArabPrueba1.csv", sep = ";")
cause= 3:23
effect= 24:44
pearson=Pearson(dataset,cause,effect)

有关如何更改文件或命令行以使其被函数识别的任何想法?可能是csv文件或其他问题?在本教程的示例中,文件直接从包中获取,因此不包括此方法。

提前谢谢

2 个答案:

答案 0 :(得分:1)

我终于解决了这个问题,即使它看起来不是一个干净的解决方案,但它确实有效。我想问题是一些额外的""当我把它们带到控制台时,它被添加到原始文件中,因此我重写了文件并将最近创建的文件重新添加到控制台。

RNA <- read.table("RNA.csv", dec = ",", sep = ";", stringsAsFactors = FALSE, header = TRUE, blank.lines.skip = TRUE)
tRNA <- t(RNA)
write.table(tRNA, file = "tRNA_2.csv", quote = FALSE, dec = ".", sep = ",", qmethod = "escape")
tRNAt <- read.csv("tRNA_2.csv")

miRNA <- read.table("miRNA.csv", dec = ",", sep = ";", stringsAsFactors = FALSE, header = TRUE, blank.lines.skip = TRUE)
tmiRNA <- t(miRNA)
write.table(tmiRNA, file = "tmiRNAt.csv", quote = FALSE, dec = ".", sep = ",", qmethod = "escape")
tmiRNAt <- read.csv("tmiRNAt.csv")

dataset <- cbind2(x=tmiRNAt, y = tRNAt)
write.table(dataset, file = "dataset_2.csv", quote = FALSE, dec = ".", sep = ",", qmethod = "escape")

# MiRLAB:
library(miRLAB)
cause = 1:278
effect = 279:length(dataset)
ps = Pearson("dataset_2.csv", cause = cause, effect = effect)

我知道写这么多次不是一个好主意,但事实上它的工作方式更好(完全有效)。

感谢您的帮助!

答案 1 :(得分:0)

这是一个例子:

# working:
# create csv file with "," seprator
write.table(x = mtcars, file = "data.csv", sep = ",", row.names = F)
Pearson(datacsv = "data.csv", cause = 2:3, effect = 3:4)

#           cyl      disp
#disp 0.9020329 1.0000000
#hp   0.8324475 0.7909486


# not work:
# create csv file with ";" seprator
write.table(x = mtcars, file = "data1.csv", sep = " ; ", row.names = F, col.names = F)
Pearson(datacsv = "data1.csv", cause = 2:3, effect = 3:4)

内部read.csv使用默认的seprator&#34;,&#34; 只需更改文件并用逗号替换所有分号