Say I have the following function:
sqrt_x = function(x) {
sqrtx = x^0.5
return(list("sqrtx" = sqrt))
}
attr(sqrt_x, "comment") <- "This is a comment to be placed on two different lines"
if I type
comment(sqrt_x)
I get
[1] "This is a comment to be placed on two different lines"
what I want, however, is that the comment is returned on two different lines (it could also be more lines and different comment elements. Any ideas appreciated.
As Andrie stated: you need to insert newline characters.
If you don’t want to have to manually specify where the newlines go, then you can use
strwrapto create breaks at convenient points, so that your string doesn’t exceed a specified width.A complete solution could look something like: