forked from yihui/knitr-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
038-output-width.Rnw
44 lines (36 loc) · 1.2 KB
/
038-output-width.Rnw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
\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}