2011-03-04 15:25:33 +01:00
|
|
|
|
|
|
|
write.ftsv <- function(data, con, name="unnamed_dataset", rowdim="rows", coldim="cols") {
|
2011-03-05 14:49:15 +01:00
|
|
|
# If con is a file name, open it
|
2011-03-04 15:25:33 +01:00
|
|
|
opened.here = FALSE
|
|
|
|
if (is.character(con)){
|
|
|
|
con = file(con, "w")
|
|
|
|
opened.here = TRUE
|
|
|
|
}
|
|
|
|
|
2011-03-05 14:49:15 +01:00
|
|
|
# Substitute all whitespace with underscores in identifiers
|
2011-03-04 15:25:33 +01:00
|
|
|
rows <- paste(gsub("\\s", "_", rownames(data)), collapse=" ")
|
|
|
|
cols <- paste(gsub("\\s", "_", colnames(data)), collapse=" ")
|
|
|
|
|
2011-03-05 14:49:15 +01:00
|
|
|
# Write header
|
2011-03-04 15:25:33 +01:00
|
|
|
writeLines(c("# type: dataset",
|
|
|
|
paste("# dimension:", rowdim, rows, collapse=' '),
|
|
|
|
paste("# dimension:", coldim, cols, collapse=' '),
|
|
|
|
paste("# name:", name, collapse=' '),
|
|
|
|
""),
|
|
|
|
con=con)
|
|
|
|
|
2011-03-05 14:49:15 +01:00
|
|
|
# Write matrix
|
2011-03-04 15:25:33 +01:00
|
|
|
write.table(data, file=con, col.names=FALSE, row.names=FALSE, sep="\t")
|
|
|
|
|
2011-03-05 14:49:15 +01:00
|
|
|
# If con was a string, close file now
|
2011-03-04 15:25:33 +01:00
|
|
|
if (opened.here)
|
|
|
|
close(con)
|
|
|
|
}
|
|
|
|
|
|
|
|
|