# NOT RUN {
x <- c("this is short", "and this is a longer text",
"whereas this is a much longer story, which could not be told shorter")
# simple truncation on 10 characters
StrTrunc(x, maxlen=10)
# NAs remain NA
StrTrunc(c(x, NA_character_), maxlen=15, wbound=TRUE)
# using word boundaries
for(i in -5:20)
print(StrTrunc(x, maxlen=i, wbound=TRUE))
# compare
for(i in -5:20)
print(StrTrunc(x, maxlen=i, wbound=FALSE))
# right justification
formatC(StrTrunc(x, maxlen=10), width=10, flag=" ")
# }
Run the code above in your browser using DataLab