Permalink
Switch branches/tags
Nothing to show
Find file
6878e8e Sep 15, 2013
45 lines (36 sloc) 1.2 KB
\documentclass{article}
\usepackage{url}
<<setup, include=FALSE>>=
options(width=60)
# an old solution by @r2d3 was at https://github.com/yihui/knitr/issues/210
# but since knitr 0.9, we can do it through the chunk option tidy.opts
@
\begin{document}
the value of $\pi$ is \Sexpr{pi}, and the function to read a table is \Sexpr{'read.table()'}.
<<test2>>=
rnorm(10)
@
<<test, tidy.opts=list(width.cutoff=30)>>=
getOption('width')
x=1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1
@
% use default global width
<<another-test>>=
getOption('width')
x=1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1
@
You can also tell knitr not to touch your source code using the chunk option tidy=FALSE, so that you can format the source code in any way you want:
<<tidy-test, tidy=FALSE>>=
1 + 1 +
1+1+
1
f = function() {
paste('I want to break the line',
'here!')
}
@
Compare the above chunk to the default behavior (tidy=TRUE):
<<tidy-test>>=
@
I only mentioned how to control the width of source code. For the width of output, it is much trickier; see \url{http://yihui.name/knitr/demo/output/}.
\end{document}