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

Writing files with different( unique) name

可能重复: 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")
    }

试试这个:

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