I need to prepare a file for a tool I am using. The file should have the structure
Mutant
Mutant:A
Expression
Gene_A:0.5 Gene_B:1 Gene_C:3
Weight: 5
I wrote the following function to create such a file, where the value for the mutant and weight are used as inputs in the function, while the expression values (ie. Gene_A: 0.5 ... Gene_C:3) are taken from a vector. In the final file, I need the expression values to be separated by \t.
prep_file <- function(mutant, expression, weight, file_name){
sink(paste0(file_name))
cat("Mutant\n")
cat(mutant,"\n")
cat("Expression\n")
cat(expression)
cat("\n")
cat("Weight:",weight)
sink()
}
That can be used as such:
expres_vec <- c("Gene_A:0.5","Gene_B:1","Gene_C:3")
prep_file("Mutant:A",expres_vec,"5","test")
To create the test file in the example above.
How can I replace the cat(expression) in order to write each element of the expres_vec separated by a tab?