Skip to contents

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.

Usage

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] "jbq qt c jbh vu vwhj c b w t" "aj rp jg ed w z ayq ib ka"   
#>  [3] "rcetw kmy ypwa pzf v rex uu"  "cd j q r nc e cw wxx s r uj" 
#>  [5] "cqk ns n a nnq w lub r op pj" "da wh mqx"                   
#>  [7] "jbq qt c jbh vu vwhj c b w t" "aj rp jg ed w z ayq ib ka"   
#>  [9] "rcetw kmy ypwa pzf v rex uu"  "cd j q r nc e cw wxx s r uj" 
#> [11] "cqk ns n a nnq w lub r op pj" "da wh mqx"                   
xfun::str_wrap(x, width = 30)  # same length as x
#> [1] "jbq qt c jbh vu vwhj c b w t\naj rp jg ed w z ayq ib ka\nrcetw kmy ypwa pzf v rex uu\ncd j q r nc e cw wxx s r uj\ncqk ns n a nnq w lub r op pj\nda wh mqx"
#> [2] "jbq qt c jbh vu vwhj c b w t\naj rp jg ed w z ayq ib ka\nrcetw kmy ypwa pzf v rex uu\ncd j q r nc e cw wxx s r uj\ncqk ns n a nnq w lub r op pj\nda wh mqx"