On Sun, Jan 15, 2012 at 4:40 PM, Francisco <franciscororol...@google.com> wrote: > Hello, > I have to write a big sentence with cat() and I would like that R > automatically adds a new line when it is needed (when the text arrives at > the end of the window), the same as Windows Notepad does (Word Wrap). > How could I do?
A little bit of research wouldn't hurt: http://en.wikipedia.org/wiki/Word_wrap#Algorithm You can split text in R with strsplit, get the length of strings with nchar, and add up the lengths with + or sum. The greedy algorithm just takes as many strings until the next one would go over the line length, and then spits those out and a new line, and carries on. The other algorithm on Wikipedia looks much more fun. Barry ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.