basically I have a bunch of text documents that have been read in via readLines
. I then want to collapse each element as a new line of a document. The paste(files,collapse=" ")
can dot his but spaces
are used.
Unfortunately using:
parsed <- lapply(files, function(x) paste(x,collapse="\n"))
embeds a literal \n
in the collapsed document. So the collapse parameter will not except special characters such as newline, tab and so on. It is entirely hard coded.
However using cat gets rid of this behaviour:
parsed <- lapply(files, function(x) cat(paste(x,collapse="\n")))
but the output is sent to the console (ie. all files). The output is correct but it is not being stored in files
Have I missed something, or does the nature of cat
not lend itself to storing output into variables?