R/truncString.R

truncString<-function(x,maxlen=20,justify="left") {
 toolong<-nzchar(x) > maxlen
 maxwidth<-ifelse(toolong,maxlen-3,maxlen)
 chopx<-substr(x,1,maxwidth)
 lenx<-length(x)
 for(i in 1:length(x)) if(toolong[i]) chopx[i]<-paste(chopx[i],"...",sep="")
 return(formatC(chopx,width=maxlen,flag=ifelse(justify=="left","-"," ")))
}

Try the prettyR package in your browser

Any scripts or data that you put into this service are public.

prettyR documentation built on May 2, 2019, 2:16 a.m.