File: RSP_intro.html.rsp

package info (click to toggle)
r-cran-r.rsp 0.45.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,568 kB
  • sloc: javascript: 612; tcl: 304; sh: 18; makefile: 16
file content (460 lines) | stat: -rw-r--r-- 11,431 bytes parent folder | download | duplicates (2)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
<%@meta language="R-vignette" content="--------------------------------
  DIRECTIVES FOR R:

  %\VignetteIndexEntry{RSP: A Brief Introduction}
  %\VignetteAuthor{Henrik Bengtsson}
  %\VignetteKeyword{R}
  %\VignetteKeyword{RSP markup language}
  %\VignetteKeyword{literate programming}
  %\VignetteKeyword{reproducible research}
  %\VignetteKeyword{report generator}
  %\VignetteKeyword{Sweave}
  %\VignetteKeyword{knitr}
  %\VignetteKeyword{brew}
  %\VignetteKeyword{noweb}
  %\VignetteKeyword{TeX}
  %\VignetteKeyword{LaTeX}
  %\VignetteKeyword{Markdown}
  %\VignetteKeyword{AsciiDoc}
  %\VignetteKeyword{reStructuredText}
  %\VignetteKeyword{Org-Mode}
  %\VignetteKeyword{HTML}
  %\VignetteKeyword{PDF}
  %\VignetteEngine{R.rsp::rsp}
  %\VignetteTangle{FALSE}
--------------------------------------------------------------------"%>
<% t0 <- Sys.time() %>
<%---------------------------------------------------------------------
  Usage:
  html <- R.rsp::rfile("RSP_intro.html.rsp")
  ---------------------------------------------------------------------%>
<%@string version="${rsp_version}" default="release"%>
<%---------------------------------------------------------------------
  SETUP
  ---------------------------------------------------------------------%>
<%
R.utils::use("R.devices")
options("devEval/args/field" = "dataURI")
devOptions("png", width = 840)
%>
<%---------------------------------------------------------------------
  RSP TEMPLATES
  ---------------------------------------------------------------------%>
<% page <- 2L; maxSlide <- 15L; %>
<% slide <- function(title) { %>
	      
---
# <%= title %>
<% } # slide() %>

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title><%@meta name="title"%></title>
  <meta name="author" content="<%@meta name="author"%>">
  <meta name="keywords" content="<%@meta name="keywords"%>">
  <style>

body {
  font-family: serif;
}

h1, h2, h3 {
  font-family: sans-serif;
  font-weight: normal;
}

section {
  font-size: 16pt;
}

h1 {
  -webkit-margin-before: 0.27em;
  -webkit-margin-after: 0.67em;
}

ul {
  padding-left: 2ex;
  list-style-position: outside;
}

li {
  margin-top: 0.75ex;
}

.remark-slide-content h1 { font-size: 140%; }
.remark-slide-content h2 { font-size: 100%; }
.remark-slide-content h3 { font-size: 90%; }

.remark-slide-content {
  font-size: 115%;
  /* Defaults: 1em 4em 1em 4em; */
  margin: 0ex;
  padding: 0em 3em 0em 3em;
}

.remark-code, .remark-inline-code {
  font-family: monospace;
  font-weight: bold;
  font-size: 90%;
}

img.screenshot-center {
   position: relative;
   bottom: 20%;
   width: 100%;
   box-shadow: 10px 10px 5px #888888;
}

img.screenshot-center-medium {
   position: relative;
   bottom: 20%;
   width: 70%;
   box-shadow: 10px 10px 5px #888888;
}

th {
   background-color: #f2f2f2;
}
tr:nth-child(even) {
   background-color: #f2f2f2
}

.blank {
  background-color: white;
}

td {
   width: 20%;
}
td:first-child {
   width: 15%;
}

#author {
  font-size: 150%;
}

.footnote-large {
  position: absolute;
  bottom: 3%;
  font-size: 120%;
}

.footnote-small {
  position: absolute;
  bottom: 5%;
  font-size: 80%;
}

  </style>
</head>
<body>
<textarea id="source" style="visibility: hidden">

# <%@meta name="title"%>

by <%@meta name="author"%>, <%=format(as.Date(R.rsp$date), format="%Y-%m-%d")%>


Available on <a href="https://cran.r-project.org/package=R.rsp">CRAN</a> since 2005 (first version ~2002):

```r
install.packages("R.rsp")
```

```r
> library("R.rsp")

> rcat("A random number: <%%= sample(1:10, size = 1) %%>")
A random number: 7
```


<%---------------------------------------------------------------------%>
<% slide("Objectives") %>
<%---------------------------------------------------------------------%>
* Dynamically generate documents and reports (and web/help pages).
* Quickly turn your favorite static report template into a dynamic one.
* Support _all_ formats, e.g. LaTeX, Markdown, HTML, ...
<%-- * Support multiple languages, e.g. R, bash, ... --%>
* Supplement and/or complement Sweave, knitr, ...
* Mix and match code and text however you want.
* Simplify sharing of template and output documents.
* Use for R package vignettes.

## Some usage
* PSCBS: PDF reports of copy-number segmentation results
* aroma-project.org: Interactive [Chromosome Explorer](http://aroma-project.org/data/reports/GSE8605/ACC,-XY,BPN,-XY,AVG,FLN,-XY,paired/ChromosomeExplorer.html) and [Array Explorer](http://www.aroma-project.org/data/reports/GSE8605/raw/ArrayExplorer.html)


<%---------------------------------------------------------------------%>
<% slide("Compiling RSP document into PDF, HTML, ...")%>
<%---------------------------------------------------------------------%>
```r
> rfile("http://example.org/vignette.tex.rsp")
RspFileProduct:
Pathname: vignette.pdf
File size: 258.71 kB (264925 bytes)
Content type: application/pdf
Metadata 'title': 'Dynamic document creation using RSP'
Metadata 'keywords': 'Literate programming, HTML, PDF'
Metadata 'author': 'Henrik Bengtsson'
```



<%---------------------------------------------------------------------%>
<% slide("Very simple idea: Translate RSP to R and evaluate")%>
<%---------------------------------------------------------------------%>
## 1. RSP document
```
Title: Example
Counting:<%% for (i in 1:3) { %%>
 <%%= i %%>
<%% } %%>
```
## 2. R script
```r
cat("Title: Example\nCounting:")
for (i in 1:3) {
  cat(" ")
  cat(i)
}
```
## 3. RSP output
```
Title: Example
Counting: 1 2 3
```

<%---------------------------------------------------------------------%>
<% slide("RSP Markup Language")%>
<%---------------------------------------------------------------------%>
## 1. RSP comments (`<%%-- ... --%%>`)
## 2. RSP preprocessing directives (`<%%@ ... %%>`)
## 3. RSP code expressions (`<%% ... %%>`)


<%---------------------------------------------------------------------%>
<% slide("RSP Markup Language")%>
<%---------------------------------------------------------------------%>
## 1. RSP comments (`<%%-- ... --%%>`)
```
<%%-----------------------------
  Compile to PDF:
  R.rsp::rfile("report.tex.rsp")
  ------------------------------%%>
\documentclass{report}
...
```
RSP comments drop anything within, e.g. private notes, other RSP constructor (nested comments too) and will never be part of the output.

<%---------------------------------------------------------------------%>
<% slide("RSP Markup Language")%>
<%---------------------------------------------------------------------%>
## 2. RSP preprocessing directives (`<%%@ ... %%>`)
### Including local and online files
```
<%%@include file="http://example.org/QC.tex.rsp"%%>
```

### Conditional inclusion
```
<%%@ifeq version="devel"%%>
  <%%@include file="templates/QA-devel.tex.rsp"%%>
<%%@else%%>
  Quality assessment is still under development.
<%%@endif%%>
```

### Meta data
```
<%%@meta title="Example"%%>
\hypersetup{pdftitle=<%%@meta name="title"%%>}
\title{<%%@meta name="title"%%>}
```

RSP preprocessing directives are independent of R, i.e. they would look the same with RSP for Python.

<%---------------------------------------------------------------------%>
<% slide("RSP Markup Language")%>
<%---------------------------------------------------------------------%>
## 3. RSP code expressions (`<%% ... %%>`)
### Insert value of evaluated R expressions
```
<%%= sample(1:100, size = 1) %%>
```

<br>

### Code snippets - mixture of RSP and text 
```
<%% for (i in 1:3) { %%>
 Step <%%= i %%>.
<%% } %%>
```



<%---------------------------------------------------------------------%>
<% slide("Looping over mixtures of code and text")%>
<%---------------------------------------------------------------------%>
```
<%% fit <- segmentByPairedPSCBS(data) %%>

\section{Segmentation results}

<%% for (chr in 1:23) { %%>
  \subsection{Chromosome <%%= chr %%>}

  <%% fitT <- extractChromosome(fit, chr) %%>
  PSCBS identified <%%= nbrOfSegments(fitT) %%> segments
  on Chr. <%%= chr %%>.

  ...
<%% } # for (chr ...) %%>
```

<br>

To achieve the same using noweb-style markup (e.g. Sweave and knitr) is tedious.



<%---------------------------------------------------------------------%>
<% slide("RSP template functions")%>
<%---------------------------------------------------------------------%>
```
<%%-- RSP TEMPLATES --%%>
<%% chromosomeSummary <- function(chr) { %%>
  <%% fitT <- extractChromosome(fit, chr) %%>
  PSCBS identified <%%= nbrOfSegments(fitT) %%> segments
  on Chr. <%%= chr %%>.
  ...
<%% } %%>

<%%-- DOCUMENT --%%>
...
<%% for (chr in 1:23) { %%>
  \subsection{Chromosome <%%= chr %%>}
  <%% chromosomeSummary(chr) %%>
<%% } # for (chr ...) %%>
```


<%---
<%---------------------------------------------------------------------%>
<% slide("RSP template functions")%>
<%---------------------------------------------------------------------%>
```
<%%-- RSP TEMPLATES --%%>
<%%@include file="http://example.org/chrSum.tex.rsp"%%>

<%%-- DOCUMENT --%%>
...
<%% for (chr in 1:23) { %%>
  \subsection{Chromosome <%%=chr%%>}
  <%% chromosomeSummary(chr) %%>
<%% } # for (chr ...) %%>
```
---%>

<%---------------------------------------------------------------------%>
<% slide("R.rsp package - RSP engine for R")%>
<%---------------------------------------------------------------------%>
## rcat() - RSP version of cat()
```r
> rcat("A random integer in [1,100]:
        <%%=sample(1:100, size = 1)%%>\n")
A random integer in [1,100]: 77
```

<br>

## rsource() - RSP version of source()
Consider RSP file 'count.rsp' (think 'count.R'):

```
Counting:<%% for (i in 1:10) { %%>
  <%% Sys.sleep(0.3) %%><%%= i %%>
<%% } %%>.
```
Running this RSP script gives:

```r
> rsource("count.rsp")
Counting: 1 2 3 4 5 6 7 8 9 10.
```

<%---------------------------------------------------------------------%>
<% slide("rfile() - end-to-end compilation")%>
<%---------------------------------------------------------------------%>
```r
> rfile("report.md.rsp", args = list(n = 50, model = "L1"))
RspFileProduct:
Pathname: report.html
File size: 42.54 kB (43564 bytes)
Content type: text/html
```

<br>

```r
> rfile("http://example.org/vignette.tex.rsp")
RspFileProduct:
Pathname: vignette.pdf
File size: 258.71 kB (264925 bytes)
Content type: application/pdf
Metadata 'title': 'Dynamic document creation using RSP'
Metadata 'keywords': 'Literate programming, HTML, PDF'
Metadata 'author': 'Henrik Bengtsson'
```


<%---------------------------------------------------------------------%>
<% slide("Including graphics (R.devices package)") %>
<%---------------------------------------------------------------------%>
RSP-embedded LaTeX

```
\includegraphics{<%%= toPDF("MyFigure,yeah,cool", {
  curve(dnorm, from = -5, to = +5)
}) %%>}
```

generates the image file and outputs

```
\includegraphics{MyFigure,yeah,cool}
```

which appears as

<img src="<%= toPNG("MyFigure,yeah,cool", aspectRatio = 0.5, {
  par(cex = 2, mar = c(4,3,1,1), mgp = c(1.8,0.5,0))
  curve(dnorm, from = -5, to = +5);
})%>" width=480>


<%---------------------------------------------------------------------%>
<% slide("Appendix") %>
<%---------------------------------------------------------------------%>
Session info:

```
<% print(sessionInfo()) %>
```

</textarea>

<script src="http://localhost/javascript/remark-slide/remark.min.js"></script>
<script>
var slideshow = remark.create({
  ratio: '4:3',
})
</script>

</body>
</html>