How to print text from a file in a knitr doc?

119 views Asked by At

I wish to read in a text file and print it verbatim in a knitr doc. I got some code to read a text file into a string:

filename = 'foo.txt'
text = readChar(filename, file.info(filename)$size)

However, my every attempt to print out the text results in ugly craziness. Using print() does not wrap the lines. It leaves "## [1]" all over the output. Using results='asis' doesn't do what I want. Trying \verbatim and \spverbatim doesn't do the right thing.

What is the easy way out here?

1

There are 1 answers

0
dfrankow On

I got this to work with

\begin{spverbatim}
\Sexpr{text}
\end{spverbatim}

not in a knitr block.