Reputation: 5694
Possible Duplicate: how to save() with a particular variable name
I need to write the output of my code, which generates some 200 files of 50k*4. I want to know if i can write each individual file with a different name in my working directory. Right now the maximum i can do is to save one file by using the code :
write.table(filename,"name.csv")
or write.csv()
.
On saving if the file with the same name exists, throw a warning and save it with a different name. Is there a way??
Edited : some code is here. Each time a file is generated, i want to write it with a unique name.
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")
}
Upvotes: 1
Views: 133
Reputation: 28379
Try this:
for(i in 1:length(affy.data)) {
...
write.table(data.full, file=paste0(i,".txt"), quote=F, sep="\t")
}
Upvotes: 1