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