2

I am providing a very simple example here. In my dataset, I have 50+ names in column. I get annoyed by the fact that colnames() output takes 50+ lines too! Is it possible to divide the output over multiple columns? Just by using some simple parameters to add to chunk. So my pdf documents are shorter.

\documentclass{article}

\begin{document}
<<>>=
library(ggplot2)
colnames(diamonds)
@
\end{document}

Sample Output

"carat"
"cut"
"color"
"clarity"
"depth"
"table"
"price"
"x"
"y"
"z" 

2 Answers 2

2

While this question would get a better answer in https://stackoverflow.com/questions/tagged/r However, try this for a vertical list

\documentclass{article}
\begin{document}
<<>>=
cat(colnames(mtcars),sep="\n")
@
\end{document}

I am still considering how to eliminate the pesky ##s

1

Upon the answer of R. Schumacher, if you show the ouput of the chunk 'asis' (as LaTeX text) you can use the LaTeX \\ as separator, and format the ouput in a 'multicols environment. This way there are no pesky ##s ;)

MWE

\documentclass{article}
\usepackage[paperheight=6cm,paperwidth=8cm,margin=1cm]{geometry}
\pagestyle{empty}
\usepackage{multicol}
\begin{document}
<<results='hide'>>=
cat(colnames(mtcars),sep="\\\\")
@
\setlength{\columnsep}{1cm}
\setlength\columnseprule{.4pt}
\begin{multicols}{3}
\noindent
<<echo=F,results='asis'>>=
cat(colnames(mtcars),sep="\\\\")
@
\end{multicols}
\end{document}
2
  • Excellent +1. I had tried the 'asis' option but didn't realize I could use "sep="\\\\" to solve the rest of the issue. I recommend talharish accept you answer. I will now go to bed very happy as I have learned something new. Apr 25, 2015 at 3:27
  • @R.Schumacher Happy that this help. :) but your solved the main part.
    – Fran
    Apr 25, 2015 at 3:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.