[R] printing an arbitrary-length character vector in columns on a page of a pdf report

Christopher W Ryan cry@n @ending from bingh@mton@edu
Tue Jun 5 18:45:20 CEST 2018

I'm writing code for a recurring report, using an R --> Sweave --> pdflatex
workflow. It includes a character vector of short words that I would like
to display compactly, in columns on a page, rather than one word per line,
which would waste a lot of space. The vector of words will increase
unpredictably over time, with future versions of the report.

I thought I would go about it by turning the character vector into a
matrix, as follows:

## set number of columns. Three for now
nc <- 3
## have to pad the character vector to a length that is multiple of nc
add <- nc - (length(dd) %% nc)
dd2 <- c(dd, rep("", add))
ddm <- matrix(dd2, ncol = nc)
latex(ddm, file = "")

Any ideas for a more elegant way to do this?


--Chris Ryan
Binghamton University
Broome County Health Department
Binghamton, NY, US

	[[alternative HTML version deleted]]

More information about the R-help mailing list