Sharedlatex-tests / system.rnwOpen in CoCalc
Author: Harald Schilly
1
\documentclass{article}
2
\usepackage[utf8]{inputenc}
3
4
\title{knitr-test}
5
\author{Harald Schilly}
6
\date{July 2018}
7
8
\begin{document}
9
10
You can type R commands in your \LaTeX{} document and they will be properly run and the output printed in the document.
11
12
13
<<>>=
14
library(knitr)
15
opts_chunk$set(fig.path='figure/latex-', cache.path='cache/latex-')
16
@
17
18
<<cache=TRUE>>=
19
# Create a sequence of numbers
20
X = 2:10
21
22
# Display basic statistical measures
23
summary(X)
24
@
25
26
t
27
28
t
29
30
t
31
32
t
33
34
t
35
36
t
37
38
<<cache=TRUE>>=
39
fileConn<-file("data.txt")
40
writeLines(paste(c(1:10), collapse=", "), fileConn)
41
close(fileConn)
42
@
43
44
and output
45
46
<<cache=TRUE>>=
47
fileConn <- file("data.txt")
48
data <- readLines(fileConn)
49
message(data)
50
@
51
52
data: \Sexpr{data}.
53
54
t
55
56
<<cache=TRUE>>=
57
system("mount", intern = TRUE)
58
@
59
60
61
<<cache=TRUE>>=
62
system("hostname", intern = TRUE)
63
@
64
65
<<cache=TRUE>>=
66
system("cat /etc/os-release", intern = TRUE)
67
@
68
69
70
<<>>=
71
system("ls -la", intern = TRUE)
72
@
73
74
<<>>=
75
system("ls -la .cache/clsi/*", intern = TRUE)
76
@
77
78
79
%/usr/lib/R/bin/exec/R --slave --no-restore -e %library('knitr');~+~setwd('/compile');~+~knit('main.Rtex')"
80
81
<<>>=
82
system("cat .project-sync-state", intern = TRUE)
83
@
84
85
<<>>=
86
system("ps aux", intern = TRUE)
87
@
88
89
ok
90
91
t
92
t
93
94
t
95
96
t
97
98
t
99
100
t
101
t
102
103
t
104
ok
105
106
<<echo=FALSE>>=
107
n <- 0
108
@
109
110
<<>>=
111
n <- n + 0
112
Sys.sleep(0)
113
message(cat(n, "secs later"))
114
@
115
116
117
118
119
t
120
121
t
122
123
ok
124
125
t
126
t
127
128
t
129
130
t
131
132
t
133
134
t
135
136
ok
137
138
t
139
t
140
141
t
142
143
t
144
145
t
146
147
t
148
149
ok
150
151
t
152
t
153
154
t
155
156
t
157
158
t
159
160
t
161
162
ok
163
164
t
165
t
166
167
t
168
169
t
170
171
t
172
173
t
174
175
ok
176
177
t
178
179
t
180
181
t
182
183
t
184
185
t
186
187
188
<<>>=
189
message(1:10)
190
@
191
192
ok
193
194
t
195
196
t
197
198
t
199
200
t
201
202
t
203
204
205
<<>>=
206
message(1:10)
207
@
208
209
ok
210
211
t
212
213
t
214
215
t
216
217
t
218
219
t
220
221
222
<<>>=
223
message(1:10)
224
@
225
226
ok
227
228
t
229
230
t
231
232
t
233
234
t
235
236
t
237
238
239
<<>>=
240
message(1:10)
241
@
242
243
244
245
\end{document}
246