Shorten strings to a given number of characters
shortenStr(str, nchar = 8)
A vector of strings of the same length as the input, with each string shortened to the desired length
Strings with more characters than nchar
will be shortened.
NA
will be kept as they are
inputStrs <- c("abc", "abcd", "abcde", NA)
shortenStr(inputStrs, nchar=4)
#> [1] "abc" "abcd" "abcd..." NA
## expected outcome: abc, abcd, abcd..., NA