I am using grid.table within the gridExtra package to display a list of survey comments in table format. When the comments(string variable) exceeds a given length I want it to automatically insert a line break "\n".
library(gridExtra)
df<-data.frame(comments = c("Here is a short string",
"Here is a long string that needs to be broken in half so that it doesn't run off the page",
"Here is another short string"))
grid.newpage()
print(grid.table(df$comments))
I am open to using a different table package if this feature is available elsewhere.
you can use strwrap,
d = sapply(lapply(df$comments, strwrap, width=50), paste, collapse="\n")
grid.table(d)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With