Re: [R] Aligning ragged text columns

From: hadley wickham <h.wickham_at_gmail.com>
Date: Wed 19 Jul 2006 - 20:53:59 EST

> I find that things line up better in data.frames

That's a good idea, although I was hoping there would be something in R to do it for me.

I have ended up with:

	fwidth <- max(nchar(x[,1]))
	descs <- strwrap(x[,2], width=width - fwidth - 5, simplify=FALSE)
	
output <- do.call(rbind, mapply(function(name, desc) {
	cbind(c(name, rep("", length=length(desc)-1)), desc)
}, x[,1], descs))         

        cat(paste(format(output[,1]), output[,2], collapse="\n"), "\n")

Thanks,

Hadley



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed Jul 19 20:57:41 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 19 Jul 2006 - 22:16:59 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.