-
Notifications
You must be signed in to change notification settings - Fork 1
/
.Rprofile
72 lines (66 loc) · 2.17 KB
/
.Rprofile
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
set.seed(100)
library("R6")
knitr::opts_chunk$set('dev' = 'png', warning = TRUE, error = TRUE,
cache = TRUE, autodep = TRUE,
fig.show = 'all',
echo = TRUE,
results = 'markup')
Counter <-
R6Class("Counter",
public =
list(i = 0L,
pattern = "%d",
initialize = function(i, pattern) {
if (!missing(i)) self$i <- i
if (!missing(pattern)) self$pattern <- pattern
},
add = function(value = 1L) {
self$i <- self$i + value
},
reset = function(value = 0L) {
self$i <- value
},
label = function() {
sprintf(self$pattern, self$i)
}
)
)
.SOLUTION_COUNTER <- Counter$new()
.CHALLENGE_COUNTER <- Counter$new()
challenge_start <- function() {
.CHALLENGE_COUNTER$add()
challenge_id <- sprintf("challenge-%s", .CHALLENGE_COUNTER$label())
string <- paste0(sprintf('<div id="%s" class="panel panel-primary">',
challenge_id),
'<div class="panel-heading">',
'<h3 class="panel-title">',
'Challenge',
'</h3>',
'</div>',
'<div class="panel-body">')
string
}
challenge_end <- function() {
string <- "</div></div>"
string
}
solution_start <- function() {
.SOLUTION_COUNTER$add()
solution_id <- sprintf("solution-%s", .SOLUTION_COUNTER$label())
string <- paste0('<div class="panel panel-info">',
'<div class="panel-heading">',
'<h3 class="panel-title">',
sprintf('<a data-toggle="collapse" href="#%s">',
solution_id),
'Solution',
'</a>',
'</h3>',
'</div>',
sprintf('<div id="%s" class="panel-collapse collapse">',
solution_id))
string
}
solution_end <- function() {
string <- "</div></div>"
string
}