使用不同(唯一)名称编写文件

时间:2015-04-08 06:37:41

标签: r writetofile

可能重复: how to save() with a particular variable name

我需要编写代码的输出,它会生成大约200个50k * 4的文件。我想知道我是否可以在工作目录中使用不同的名称编写每个单独的文件。现在我可以做的最大值是使用代码保存一个文件:

write.table(filename,"name.csv")write.csv()

如果存在具有相同名称的文件,则保存时,抛出警告并使用其他名称保存。有办法吗?

编辑:有些代码在这里。每次生成文件时,我都想用唯一的名称编写它。

      affy.data = ReadAffy()
      for(i in 1: length(affy.data))
      {

       eset.mas5 = mas5(affy.data[,i])

    ## getting the expression matrix (probesets/genes in rows, chips in columns).
    exprSet.nologs = exprs(eset.mas5)

    ## At this time let's log-transform the expression values to get a more normal distribution. 
    ## We have to remember we've done this when we calculate ratios. Logarithms can use any
    ## base, but base 2 is easiest when transforming ratios, since transformed 2-fold
    ## ratios up or down will be +1 or -1. As a result, we'll do all logs with base
    ## 2 to keep thing simplest.
    #exprSet = log(exprSet.nologs, 2)


    ## While we're doing Affymetrix-specific preprocessing, let's calculate an Absent/Present call for each probeset.
    # Run the Affy A/P call algorithm on the CEL files we processed above
    data.mas5calls = mas5calls(affy.data[,i])

    # Get the actual A/P calls
    data.mas5calls.calls = exprs(data.mas5calls)

    ## Getting pvalue
    pvalue <- assayData(data.mas5calls)[["se.exprs"]]

    ## Combining data
    data.full <- cbind(exprSet.nologs,data.mas5calls.calls,pvalue)
    colnames(data.full) <- c("VALUE","ABS_CALL","DETECTION P-VALUE")
    print(head(data.full,20))
    write.table(data.full, file="1.txt", quote=F, sep="\t")
    }

1 个答案:

答案 0 :(得分:1)

试试这个:

for(i in 1:length(affy.data)) {
    ...
    write.table(data.full, file=paste0(i,".txt"), quote=F, sep="\t")
}