Skip to contents

Slice/split a string into multiple lines by the desired length of the line.

Usage

str_slice(x, n = 80L)

str_slice_by_word(x, n = 80L)

Arguments

x

A character vector

n

Integer, the length of the line split

Value

A character vector

Examples

if (requireNamespace("stringi")) {
  x <- stringi::stri_rand_lipsum(1)
  str_slice(x)
  str_slice_by_word(x, n = 50L)
}
#>  [1] "Lorem ipsum dolor sit amet, volutpat dapibus"      
#>  [2] "egestas sagittis felis in leo efficitur felis."    
#>  [3] "Enim nisi eu libero, sed nullam metus mauris,"     
#>  [4] "ipsum quisque. Sed velit neque urna vitae"         
#>  [5] "elementum sed ac sit a, maximus. Dis ultrices est."
#>  [6] "At id ac sed, lorem. Mauris lacinia, ac lobortis"  
#>  [7] "ultrices conubia sed at risus nec habitant? Eu ac,"
#>  [8] "euismod congue id donec. Lorem vivamus id nec"     
#>  [9] "euismod, phasellus. Sit est mauris lorem, ipsum"   
#> [10] "porttitor litora, gravida dolor ac duis sit. Magna"
#> [11] "iaculis tortor nam pellentesque ridiculus"         
#> [12] "efficitur sed placerat. Praesent cursus. Neque,"   
#> [13] "bibendum ex nullam in quisque elementum in,"       
#> [14] "efficitur. Sed vitae sagittis a conubia penatibus,"
#> [15] "nullam pharetra donec sociosqu mus."