简体   繁体   English

R中的write.table创建txt文件,然后错误读取

[英]write.table in R creates txt files that it then reads incorrectly

So I am working in MethylKit that has a function that necessitates the use of txt files. 因此,我在MethylKit中工作,该工具具有必须使用txt文件的功能。

My original files of my data work perfectly, but due to some other issues I am troubleshooting by creating subsets of my original files. 我的数据原始文件运行正常,但是由于其他一些问题,我正在通过创建原始文件的子集来进行故障排除。

To do so I am using: 为此,我正在使用:

write.table(head(Sample_101, n=100),"shorty_101.txt", col.names = FALSE, 
sep = "\t", row.names = TRUE)

I was at first running into the issue of R shifting the column names and the above line works well for fixing that issue. 起初,我遇到了R转换列名的问题,上面的代码行很好地解决了该问题。 However, when I attempt to put the txt files into the file.listshorty object that will then be used for the methRead function, I get this: 但是,当我尝试将txt文件放入file.listshorty对象中,该对象随后将用于methRead函数时,我得到了:

file.listshorty <- list("shorty_101.txt","shorty_102.txt", "shorty_103.txt", 
                    "shorty_104.txt", "shorty_105.txt", "shorty_107.txt")


myobjS = methRead(file.listshorty, sample.id=list("Sample_101_GDM", 
"Sample_102_GDM", "Sample_103_GDM", "Sample_104_nonGDM", 
"Sample_105_nonGDM", "Sample_107_nonGDM"), assembly = "hg19", 
treatment=c(1,1,1,0,0,0), context="CpG", dbtype = "tabix", pipeline = "amp", 
header= TRUE, skip = 0, sep = "\t", resolution = "base", dbdir = getwd(), 
mincov = 10)

Error in data[, 5] * data[, 6] : non-numeric argument to binary operator

However when I open these txt files created by R and remove the extraneous things added to it and then read them in, it works... 但是,当我打开由R创建的这些txt文件并删除添加到其中的无关紧要的东西,然后读入它们时,它就可以工作了...

To clarify --> Removed the row numbering column and the row that names the columns V1, V2, V3...V7. 要澄清->删除了行编号列和命名列V1,V2,V3 ... V7的行。

 V1 V2 V3 V4 V5 V6 V7
1
2
3
4
5

I have also tried to do: 我也尝试做:

write.table(head(Sample_101, n=100), "shorty_101.txt", col.names = FALSE, 
sep = "\t", row.names = FALSE)

It gives me the same error message. 它给了我同样的错误信息。 I am assuming it is because the first row needs to be denoted as the header but not sure how to do this using the list function or if there is another work around. 我假设这是因为第一行需要表示为标题,但不确定如何使用列表功能或是否还有其他解决方法。

Any help is much appreciated! 任何帮助深表感谢!

Thanks! 谢谢!

Figured it out! 弄清楚了! You have to take out the quotes that are created in the txt file by adding the argument quote = FALSE in the write.table function. 您必须通过在write.table函数中添加参数quote = FALSEwrite.table txt文件中创建的引号。

write.table(head(Sample_101, n=100), "shorty_101.txt", col.names = FALSE, sep 
= "\t", row.names = FALSE, quote = FALSE)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM