Closed jeromyanglim closed 12 years ago
This thread on word wrapping on R Help assisted
Take this example string:
x <- 'This is a long sentence that needs to be broken over multiple lines'
Then apply the following command
paste0(strwrap(x, width=30), collapse='\n')
paste0
: a functino that combines strings; collapse
is an argument that specifies a separator when combining multiple elements of a character vector. In this case I use the line separator \n
strwrap
: function that breaks strings into separate elements of a character vector. Width is the number of columns before wrapping.It produces:
"This is a long sentence that\nneeds to be broken over\nmultiple lines"
I have a set of survey items which I want to show as titles to individual graphs. I want the titles to automatically wrap over multiple lines as required.
What is a good strategy for implementing a form of word wrapping in R?