-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.R
executable file
·245 lines (227 loc) · 11.8 KB
/
setup.R
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
# Learnitdown configuration and functions
learnitdown <- list(
baseurl = "https://wp.sciviews.org", # The base URL for the site
imgbaseurl =
"https://filedn.com/lzGVgfOGxb6mHFQcRn9ueUb/sdd-umons", # The base URL for external (big) images
shiny_imgdir = "images/shinyapps", # The Shiny image directory (screenshots)
svbox = 2024, # The SciViews Box version used
rstudio = "start_rstudio2024.html", # Run Rstudio from the box
package = "BioDataScience1", # Associated package for the exercises
institutions = "UMONS", # Known institutions
courses = c(
"S-BIOG-006", # SDD1 Q1 Mons
"S-BIOG-027" #, # SDD1 Q2 Mons
#"S-BIOG-921" # SDD1 Charleroi
),
courses_names = c(
"Science des Données Biologiques I : visualisation à l'UMONS",
"Science des Données Biologiques I : inférence à l'UMONS" #,
#"Bio-Informatique et Science des Données à Charleroi"
),
acad_year = "2024-2025", # The academic year
YY = 24, # The academic year short id
W = as.Date("2024-09-08") + (0:37)*7, # Sundays before each academic week
Q1 = as.Date("2024-09-08") + (0:15)*7, # There are 15 weeks at Q1
Q2 = as.Date("2025-02-02") + c(0:11, 14:16)*7 # Q2 starts 02/02 w22 but w33-34 are holidays
)
# We use glue() often for variables replacement from learnitdown, so, we
# define the `!` operator for character objects to glue the string
# Cons: it slightly slows down the usual `!` operator (10x slower)
`!` <- function(x) {
if (is.character(x)) {
as.character(glue::glue_data(learnitdown, x))
} else {# Usual ! operator
.Primitive('!')(x)
}
}
# Examples:
#!"svbox{svbox} is for academic year {acad_year}"
# -> svbox2024 is for academic year 2024-2025
#microbenchmark::microbenchmark(!TRUE, .Primitive('!')(TRUE), .Primitive('!'))
# Unary + binary + is nice too, but it slows down additions!
# We use glue() often for variables replacement from learnitdown, so, we
# redefine the unary and binary `+` operators for character objects
#`+` <- function(e1, e2) {
# if (missing(e2)) {# Unary operator
# if (inherits(e1, "character")) {
# glue::glue_data(learnitdown, e1)
# } else {# Usual + operator
# .Primitive("+")(e1)
# }
# glue::glue_data(learnitdown, e1)
# } else {# Binary operator
# if (inherits(e1, "character")) {
# glue::as_glue(paste0(e1, glue::glue_data(learnitdown, e2)))
# } else {# Usual + operator
# .Primitive("+")(e1, e2)
# }
# }
#}
# Examples:
#+"svbox{svbox} is for academic year {acad_year}"
# -> svbox2024 is for academic year 2024-2025
#+"svbox{svbox}" + " is for" + " academic year {acad_year}"
# -> same result
# With the new R 4.0 character strings syntax:
#+r"("{courses[1]}" est le cours de {courses_names[1]})"
# -> "S-BIOG-015" est le cours de Science des Données Biologiques II à l'UMONS
# Date are better defined according to the academic calendar. So, W[1]+1 is
# monday of first week and W[15]+5 is friday of last Q1 week
#+"Q1 starts {W[1]+1} 08:15:00 and ends {W[15]+5} 17:45:00"
# -> Q1 starts 2021-09-13 08:15:00 and ends 2021-12-24 17:45:00
## Big images (animated gifs, ...) are stored externally, refer them this way:
#
# `r img("sub_dir", "image_name.gif")`
# or to add a caption (use ''' instead of ` if you need it in your caption):
# # `r img("sub_dir", "image_name.gif", caption = "A nice picture.")`
## h5p(), launch_shiny(), learnr() & assignation() for exercises blocks, use:
#
# `r h5p(x, toc = "Short description")`
#
# `r launch_shiny(url, toc = "Short description")`
#
# `r learnr(id, title = "...", toc = "Short description")`
#
#```{r assign_A01Ia_markdown, echo=FALSE, results='asis'}
#if (exists("assignment"))
# assignment("A01Ia_markdown", part = NULL,
# url = "https://github.com/BioDataScience-Course/A01Ia_markdown",
# course.ids = c(
# 'S-BIOG-015' = +"A01Ia_{YY}M_markdown",
# 'S-BIOG-937-958-959' = +"A01Ia_{YY}C_markdown",
# 'late_mons' = +"A01Ia_{YY}M_markdown"),
# course.urls = c(
# 'S-BIOG-015' = "https://classroom.github.com/a/...",
# 'S-BIOG-937-958-959' = "https://classroom.github.com/a/...",
# 'late_mons' = "https://classroom.github.com/a/..."),
# course.starts = c(
# 'S-BIOG-015' = +"{W[1]+1} 08:00:00",
# 'S-BIOG-937-958-959' = NA, # Nondefined date, or just ignore it
# 'sdd1late' = +"{W[1]+1} 08:00:00"),
# course.ends = c(
# 'S-BIOG-015' = +"{W[3]+5} 23:59:59",
# 'sdd1late' = +"{W[5]+5} 23:59:59"),
# term = "Q1", level = 3,
# toc = "Réalisation d'un premier document en Markdown")
#```
# Use assignment2() for group assignment, and challenge() or challenge2()
# for assignments that are linked to challenges
#
# Then, at the end of the module, create the exercises toc with:
#
# `r show_ex_toc()`
#
# Use `r learnitdown::clean_ex_toc()` at the beginning of index.Rmd to
# make sure the ex dir is clean when the book compiles
img <- function(..., caption = "") {
path <- paste(learnitdown$imgbaseurl, ..., sep = "/")
# Cannot use ` inside R code => use ''' instead
caption <- gsub("'''", "`", caption)
paste0("![", caption, "](", path, ")")
}
h5p <- function(id, toc = "", ...)
learnitdown::h5p(id, toc = toc, baseurl = learnitdown$baseurl,
toc.def = "Exercice H5P {id}",
h5p.img = "images/list-h5p.png",
h5p.link = paste(learnitdown$baseurl, "h5p", sep = "/"), ...)
launch_shiny <- function(url, toc = "", fun = paste(learnitdown$package, "run_app", sep = "::"),
#ENalt1 = "*Click to start the Shiny application*",
alt1 = "*Cliquez pour lancer l'application Shiny.*",
#ENalt2 = "*Click to start or [run `{run.cmd}`]({run.url}{run.arg}) in RStudio.*",
alt2 = "*Cliquez pour lancer ou [exécutez dans RStudio]({run.url}{run.arg}){{target=\"_blank\"}} `{run.cmd}`.*", ...)
learnitdown::launch_shiny(url = url, toc = toc, imgdir = learnitdown$shiny_imgdir,
fun = fun, alt1 = alt1, alt2 = alt2, toc.def = "Application Shiny {app}",
run.url = paste(learnitdown$baseurl, "/", learnitdown$rstudio, "?runrcode=", sep = ""),
app.img = "images/list-app.png",
app.link = paste(learnitdown$baseurl, "shiny_app", sep = "/"), ...)
launch_report <- function(module, course = "S-BIOG-006", toc = NULL, fun = NULL,
#ENalt1 = "*Click to see the progress report.*",
alt1 = "*Cliquez pour visualiser le rapport de progression.*",
#ENalt2 = "*Click to calculate your progress report for this module.*",
alt2 = "*Cliquez pour calculer votre rapport de progression pour ce module.*",
height = 800, ...)
learnitdown::launch_shiny(url =
paste0("https://sdd.umons.ac.be/sdd-progress-report?course=", course,
"&module=", module),
toc = toc, imgdir = learnitdown$shiny_imgdir,
fun = fun, alt1 = alt1, alt2 = alt2, toc.def = "Progress report {app}",
run.url = paste(learnitdown$baseurl, "/", learnitdown$rstudio, "?runrcode=", sep = ""),
app.img = "images/list-app.png",
app.link = paste(learnitdown$baseurl, "shiny_app", sep = "/"), height = height, ...)
# Note: not used yet!
launch_learnr <- function(url, toc = "", fun = paste(learnitdown$package, "run", sep = "::"), ...)
launch_shiny(url = url, toc = toc, fun = fun, ...)
learnr <- function(id, title = NULL, toc = "", package = learnitdown$package,
text = "Effectuez maintenant les exercices du tutoriel")
learnitdown::learnr(id = id, title = title, package = package, toc = toc,
text = text, toc.def = "Tutoriel {id}",
rstudio.url = paste(learnitdown$baseurl, learnitdown$rstudio, sep = "/"),
tuto.img = "images/list-tuto.png",
tuto.link = paste(learnitdown$baseurl, "tutorial", sep = "/"))
# Note: use course.urls = c(`S-BIOG-006` = "classroom url1", `S-BIOG-921` = "classroom url2"), and url = link to Github template repository for the assignment
assignment <- function(name, url, course.ids = NULL, course.urls = NULL,
course.starts = NULL, course.ends = NULL, part = NULL, toc = "", clone = TRUE,
level = 3, n = 1, type = "ind. github", acad_year = !"{acad_year}",
term = "Q1", texts = learnitdown::assignment_fr())
learnitdown::assignment(name = name, url = url, course.ids = course.ids,
course.urls = course.urls, course.starts = course.starts,
course.ends = course.ends, part = part,
course.names = stats::setNames(learnitdown$courses_names,
learnitdown$courses), toc = toc, clone = clone, level = level, n = n,
type = type, acad_year = acad_year, term = term, texts = texts,
assign.img = "images/list-assign.png",
assign.link = paste(learnitdown$baseurl, "github_assignment", sep = "/"),
template = "assignment_fr.html", baseurl = learnitdown$baseurl)
assignment2 <- function(name, url, course.ids = NULL, course.urls = NULL,
course.starts = NULL, course.ends = NULL, part = NULL, toc = "", clone = TRUE,
level = 4, n = 2, type = "group github", acad_year = !"{acad_year}",
term = "Q1", texts = learnitdown::assignment2_fr())
learnitdown::assignment2(name = name, url = url, course.ids = course.ids,
course.urls = course.urls, course.starts = course.starts,
course.ends = course.ends, part = part,
course.names = stats::setNames(learnitdown$courses_names,
learnitdown$courses), toc = toc, clone = clone, level = level, n = n,
type = type, acad_year = acad_year, term = term, texts = texts,
assign.img = "images/list-assign2.png",
assign.link = paste(learnitdown$baseurl, "github_assignment", sep = "/"),
template = "assignment_fr.html", baseurl = learnitdown$baseurl)
challenge <- function(name, url, course.ids = NULL, course.urls = NULL,
course.starts = NULL, course.ends = NULL, part = NULL, toc = "", clone = TRUE,
level = 3, n = 1, type = "ind. challenge", acad_year = !"{acad_year}",
term = "Q1", texts = learnitdown::challenge_fr())
learnitdown::challenge(name = name, url = url, course.ids = course.ids,
course.urls = course.urls, course.starts = course.starts,
course.ends = course.ends, part = part,
course.names = stats::setNames(learnitdown$courses_names,
learnitdown$courses), toc = toc, clone = clone, level = level, n = n,
type = type, acad_year = acad_year, term = term, texts = texts,
assign.img = "images/list-challenge.png",
assign.link = paste(learnitdown$baseurl, "github_challenge", sep = "/"),
template = "assignment_fr.html", baseurl = learnitdown$baseurl)
challenge2 <- function(name, url, course.ids = NULL, course.urls = NULL,
course.starts = NULL, course.ends = NULL, part = NULL, toc = "", clone = TRUE,
level = 4, n = 2, type = "group challenge", acad_year = !"{acad_year}",
term = "Q1", texts = learnitdown::challenge2_fr())
learnitdown::challenge2(name = name, url = url, course.ids = course.ids,
course.urls = course.urls, course.starts = course.starts,
course.ends = course.ends, part = part,
course.names = stats::setNames(learnitdown$courses_names,
learnitdown$courses), toc = toc, clone = clone, level = level, n = n,
type = type, acad_year = acad_year, term = term, texts = texts,
assign.img = "images/list-challenge2.png",
assign.link = paste(learnitdown$baseurl, "github_challenge", sep = "/"),
template = "assignment_fr.html", baseurl = learnitdown$baseurl)
# Note: use `r learnitdown::clean_ex_toc()` at the beginning of index.Rmd to
# make sure the ex dir is clean when the book compiles.
show_ex_toc <- function(header = "", clear.it = TRUE)
learnitdown::show_ex_toc(header = header, clear.it = clear.it)
# Include javascript and css code for {learnitdown} additional features
# in style.css and header.html, respectively
learnitdown::learnitdown_init(
baseurl = learnitdown$baseurl,
#EN hide.code.msg = "See the code",
hide.code.msg = "Voir le code",
institutions = learnitdown$institutions,
courses = learnitdown$courses)
# Knitr default options
knitr::opts_chunk$set(comment = "#", fig.align = "center")