From 80e64afd04a0f86c6c54b8ee5e9032746b29c0bc Mon Sep 17 00:00:00 2001 From: einarr Date: Fri, 4 Mar 2011 14:25:33 +0000 Subject: [PATCH] Renamed R package to R. --- R/laydi.R | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 R/laydi.R diff --git a/R/laydi.R b/R/laydi.R new file mode 100644 index 0000000..54f878a --- /dev/null +++ b/R/laydi.R @@ -0,0 +1,30 @@ + +write.ftsv <- function(data, con, name="unnamed_dataset", rowdim="rows", coldim="cols") { + /* If con is a file name, open it */ + opened.here = FALSE + if (is.character(con)){ + con = file(con, "w") + opened.here = TRUE + } + + /* Substitute all whitespace with underscores in identifiers */ + rows <- paste(gsub("\\s", "_", rownames(data)), collapse=" ") + cols <- paste(gsub("\\s", "_", colnames(data)), collapse=" ") + + /* Write header */ + writeLines(c("# type: dataset", + paste("# dimension:", rowdim, rows, collapse=' '), + paste("# dimension:", coldim, cols, collapse=' '), + paste("# name:", name, collapse=' '), + ""), + con=con) + + /* Write matrix */ + write.table(data, file=con, col.names=FALSE, row.names=FALSE, sep="\t") + + /* If con was a string, close file now */ + if (opened.here) + close(con) +} + +