A wrapper function to make strwrap() return a character vector of the same length as the input vector; each element of the output vector is a string formed by concatenating wrapped strings by \n.

str_wrap(...)

Arguments

...

Arguments passed to strwrap().

Value

A character vector.

Examples

x = sample(c(letters, " "), 200, TRUE, c(rep(0.5/26, 26), 0.5))
x = rep(paste(x, collapse = ""), 2)
strwrap(x, width = 30)
#>  [1] "bh vu vwhj c b w t aj rp jg"   "ed w z ayq ib ka rcetw kmy"   
#>  [3] "ypwa pzf v rex uu cd j q r nc" "e cw wxx s r uj cqk ns n a"   
#>  [5] "nnq w lub r op pj da wh"       "mqxwcu y l b s"               
#>  [7] "bh vu vwhj c b w t aj rp jg"   "ed w z ayq ib ka rcetw kmy"   
#>  [9] "ypwa pzf v rex uu cd j q r nc" "e cw wxx s r uj cqk ns n a"   
#> [11] "nnq w lub r op pj da wh"       "mqxwcu y l b s"               
xfun::str_wrap(x, width = 30)  # same length as x
#> [1] "bh vu vwhj c b w t aj rp jg\ned w z ayq ib ka rcetw kmy\nypwa pzf v rex uu cd j q r nc\ne cw wxx s r uj cqk ns n a\nnnq w lub r op pj da wh\nmqxwcu y l b s"
#> [2] "bh vu vwhj c b w t aj rp jg\ned w z ayq ib ka rcetw kmy\nypwa pzf v rex uu cd j q r nc\ne cw wxx s r uj cqk ns n a\nnnq w lub r op pj da wh\nmqxwcu y l b s"