regex - Automatically inserting line breaks in long string -
is possible insert line breaks character string automatically adjust don't split words?
nif <- as.character(c("i string", "so i", "i string way long"))
i found code in post splits words , add line break after each string avoid
gsub('(.{1,20})', '\\1\n',nif)
the output going this:
"i string" "so i" "i string \n way long"
you can use strwrap
.
strwrap(nif, 20) # [1] "i string" "so i" "i string" # [4] "but way long" sapply( strwrap(nif, 20, simplify=false), paste, collapse="\n" ) # [1] "i string" "so i" # [3] "i string\nbut way long"
Comments
Post a Comment