I have a list of character vectors, and I would like to write the list to a single file with all the character vectors. Here is an example of what I need:
>str(mylist)
List of 19
$ geneset1 : chr [1:140] "ASGR2" "ATXN7L3" "BCL6B" "C6orf211" ...
$ geneset2 : chr [1:174] "CKS1B" "CREBL2" "CTNNB1" "CTTN" ...
$ geneset3 : chr [1:346] "AGTR1" "C6" "C6orf211" "CCNK" ...
$ geneset4 : chr [1:259] "ASGR2" "ATF7IP" "ATXN7L3" "CKS1B" ...
My desired output would be a file like this:
#myfile
>geneset1
ASGR2 ATXN7L3 BCL6B C6orf211
>geneset2
ASGR2 ATXN7L3 BCL6B C6orf211
>geneset3
AGTR1 C6 C6orf211 CCNK
My approach is this:
writeLines(unlist(lapply(mylist, FUN=function(x)paste(x, collapse=" "))), con="test.txt")
However, I don't know how to add ">" at the beginning of the line
Thanks