set.seed(1234)
long.string <- paste("This is a very long string, composed from the following words:",
paste(sample(c("one","two","three"), 60, replace=TRUE), collapse=""))
long.string
string.vector <- unlist(strsplit(long.string, ""))
# a row length of 70, no space at the beginning
cat(prettyString(string.vector, 70, 0, ""), "")
# a row length of 50, inserting 7 spaces before each row
cat("", prettyString(string.vector, 50, 7, ""), "")
Run the code above in your browser using DataLab