CoCalc Shared Fileslatex-tests / test.rnw
Author: Harald Schilly
1\documentclass{article}
2\usepackage[utf8]{inputenc}
3\usepackage[T1]{fontenc}
4\usepackage{url}
5
6
7\title{Knitr in CoCalc}
8
9\author{Harald Schilly}
10
11\begin{document}
12
13\maketitle
14
15You can type R commands in your \LaTeX{} document and they will be properly run and the output printed in the document.
16
17<<>>=
18library(knitr)
19opts_chunk\$set(fig.path='figure/latex-', cache.path='cache/latex-')
20@
21
22<<>>=
23R.version
24@
25
26<<>>=
27ip <- installed.packages()
28dim(ip)
29@
30
31<<cache=TRUE>>=
32# Create a sequence of numbers
33X = 2:10
34
35# Display basic statistical measures
36summary(X)
37@
38
39<<>>=
40myF <- function(x) {
41    print(2*x + 1)
42}
43myF(22)
44@
45
46$$x^y$$
47
48<<>>=
49a <- 111
50@
51
52<<>>=
53x <- c(2,3,4,5,1,2,3,2)
54summary(x)
55@
56
57<<histogram-plot, fig.width=6, fig.height=4, out.width='.75\\linewidth'>>=
58hist(x)
59@
60
61Sum of \Sexpr{paste(x, collapse="+")} is \Sexpr{sum(x)}.
62
63test
64
65test 123
66
67test
68
69test
70
71test
72
73test
74
75test
76
77test
78
79test
80
81test
82
83test
84
85test
86
87test
88
89test
90
91test
92
93
94
95where am I? here.
96
97t
98
99t
100
101t
102
103asdf
104
105t
106
107t
108
109t
110
111t
112
113t
114
115t
116
117t
118
119t
120
121t
122
123t
124123
125
126t
127
128
129this line
130
131t
132
133t
134
135t
136
137<<histogram-plot2, fig.width=8, fig.height=4, out.width='.4\\linewidth'>>=
138hist(x)
139@
140
141t
142
143t
144
145t
146
147ok
148
149t
150
151t
152
153t
154
155t
156
157t
158
159t
160
161<<histogram-plot3, fig.width=4, fig.height=4, out.width='.4\\linewidth'>>=
162hist(x)
163@
164t
165
166t
167
168t
169
170t
171
172t
173
174t
175
176t
177
178t
179
180t
181
182\pagebreak
183
184<<histogram-plot4, dev='tikz', fig.height=4, fig.width=10, out.width='.9\\linewidth'>>=
185data <- rnorm(1000)
186hist(data)
187@
188
189\Sexpr{1/17} and \Sexpr{1.23e-6}.
190
191EOF
192
193\end{document}
194
195
196