-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.R
More file actions
executable file
·332 lines (309 loc) · 17.3 KB
/
setup.R
File metadata and controls
executable file
·332 lines (309 loc) · 17.3 KB
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
# Learnitdown configuration and functions
# 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)
}
}
# General configuration data
learnitdown <- list(
baseurl = "https://wp.sciviews.org", # The base URL for the site
connecturl = "https://sdd.umons.ac.be", # The URL for the Posit Connect server
imgbaseurl =
"https://filedn.com/lzGVgfOGxb6mHFQcRn9ueUb/sdd-umons2", # The base URL for external (big) images
shiny_imgdir = "images/shinyapps", # The Shiny image directory (screenshots)
svbox = 2025, # The SciViews Box version used
rstudio = "start_rstudio2025.html", # Run RStudio from the box
package = "BioDataScience2", # Associated package for the exercises
institutions = "UMONS", # Known institutions
sets = "25M", # The course set (in case there are several ones)
courses = c(
"S-BIOG-015", # SDD2 Q1
"S-BIOG-061" #, # SDD2 Q2
#"S-BIOG-937-958-959" # SDD2 Charleroi
),
courses_names = c(
"Science des Données Biologiques II à l'UMONS (Q1 : modélisation)",
"Science des Données Biologiques II à l'UMONS (Q2 : analyse)" #,
#"Bioinformatique et Science des Données II à Charleroi"
),
terms = c("Q1", "Q2"), # The term of each course
acad_year = "2025-2026", # The academic year
YYYY = 2025, # The academic year long id
YY = 25, # The academic year short id
W = as.Date("2025-09-07") + (0:37)*7, # Sundays before each academic week
Q1 = as.Date("2025-09-07") + (0:15)*7, # There are 15 weeks at Q1
Q2 = as.Date("2026-02-01") + c(0:11, 14:16)*7 # Q2 starts 02/02 w22 but w33-34 are holidays
)
# Course start and end dates
learnitdown$course_start <- !"{W[2]+1}"
learnitdown$course_end <- !"{W[35]+2}"
# Modules dates
learnitdown$mod <- as.data.frame(tibble::tribble(
~id, ~term, ~start, ~class1, ~end, ~class2, ~N3, ~N4, ~challenge, ~test,
# Q1
"install", "Q1", !"{W[2]+1}", "10:30-12:30", "-", "-", "-", "-", "-", "-",
"B01", "Q1", !"{W[4]+1}", "10:30-12:30", !"{W[4]+5}", "08:15-12:30", !"{W[5]+1}", "-", "-", !"{W[4]+5}",
"B02", "Q1", !"{W[7]+1}", "10:30-12:30", !"{W[7]+4}", "08:15-12:30", !"{W[8]+1}", !"{W[7]+4}", "-", !"{W[7]+4}",
"B03", "Q1", !"{W[9]+1}", "10:30-12:30", !"{W[9]+4}", "08:15-12:30", !"{W[10]+1}", "continue...", "-", !"{W[9]+4}",
"B04", "Q1", !"{W[11]+1}", "10:30-12:30", !"{W[11]+4}", "08:15-12:30", !"{W[12]+1}", "continue...", "-", !"{W[11]+4}",
"B05", "Q1", !"{W[13]+1}", "10:30-12:30", !"{W[13]+4}", "08:15-12:30", !"{W[14]+1}", !"{W[15]+2}", !"{W[13]+4}", "-",
"remed", "Q1", !"{W[15]+1}", "10:30-12:30", "-", "-", "-", "-", "-", "-",
# Q2
"B06", "Q2", !"{W[22]+1}", "13:30-15:30", !"{W[22]+5}", "08:15-12:30", !"{W[23]+1}", "-", "-", !"{W[22]+5}",
"B07", "Q2", !"{W[24]+1}", "13:30-15:30", !"{W[24]+5}", "08:15-12:30", !"{W[25]+1}", "-", !"{W[24]+5}", "-",
"B08", "Q2", !"{W[26]+1}", "13:30-15:30", !"{W[26]+5}", "08:15-12:30", !"{W[27]+1}", "-", "-", !"{W[26]+5}",
"B09", "Q2", !"{W[30]+1}", "13:30-15:30", !"{W[30]+5}", "08:15-12:30", !"{W[31]+1}", !"{W[30]+5}", "-", !"{W[30]+5}",
"B10", "Q2", !"{W[32]+1}", "13:30-15:30", !"{W[32]+5}", "08:15-12:30", !"{W[33]+1}", !"{W[35]+2}", "-", !"{W[32]+5}"
))
rownames(learnitdown$mod) <- learnitdown$mod$id
# Assignment URLS
learnitdown$assign_url <- list(
# Q1
B00Qa_issues = "https://classroom.github.com/a/jqxThXQx",
B01Ia_debug = "https://classroom.github.com/a/85GhxkmV",
B01Ib_abalone = "https://classroom.github.com/a/j-TzW9Ms",
B02Ia_achatina = "https://classroom.github.com/a/179dfmUZ",
B02Ga_models = "https://classroom.github.com/a/kaCKEi-H",
B03Ia_who = "https://classroom.github.com/a/hH-yrrIc",
B04Ia_lungcap = "https://classroom.github.com/a/8sp4WmRa",
B05Ia_abies_balsamea = "https://classroom.github.com/a/0rhjeqUM",
B05Ca_models = "https://classroom.github.com/a/...",
# Q2
B06Ia_fish_market = "https://classroom.github.com/a/jKW9Yt6H",
B06Ga_open_data = "https://classroom.github.com/a/9Y7xILiH",
B07Ia_acp_afc = "https://classroom.github.com/a/sheuR9QS",
B07Ca_multi = "https://classroom.github.com/a/...",
B08Ia_mfa = "https://classroom.github.com/a/EcAqwuZ0",
B08Ib_zooscannet = "https://classroom.github.com/a/MyO1yWPo",
B09Ia_portalr = "https://classroom.github.com/a/G2No12XP"
)
# Date and time for start and end of classes for each module
class1_start <- function(x, module)
paste0(x[module, 'start'], " ", substring(x[module, 'class1'], 1, 5), ":00")
class1_end <- function(x, module)
paste0(x[module, 'start'], " ", substring(x[module, 'class1'], 7, 11), ":00")
class2_start <- function(x, module)
paste0(x[module, 'end'], " ", substring(x[module, 'class2'], 1, 5), ":00")
class2_end <- function(x, module)
paste0(x[module, 'end'], " ", substring(x[module, 'class2'], 7, 11), ":00")
n3_end <- function(x, module, hour = "23:59:59")
paste0(x[module, 'N3'], " ", hour)
n4_end <- function(x, module, hour = "23:59:59")
paste0(x[module, 'N4'], " ", hour)
# Link inside the courses: the link are a little bit more complex because the
# bookdown is embedded in a Wordpress site. A direct link like:
# https://wp.sciviews.org/sdd-umons2-2025/outils-de-diagnostic-suite.html#résumé-avec-summarysuite
# becomes:
# https://wp.sciviews.org/sdd-umons2/?iframe=wp.sciviews.org/sdd-umons2-2025/outils-de-diagnostic-suite.html%23résumé-avec-summarysuite
course_link <- function(label, course = 1, page, anchor = "", year = !"{YYYY}",
baseurl = !"{baseurl}", course_page = "sdd-umons") {
if (course == 1) {
course <- ""
} else{
course <- as.character(course)
}
if (anchor != "")
anchor <- paste0("%23", anchor) # %23 is the URLencoded value of '#'
baseurl2 <- sub("https://", "", baseurl, fixed = TRUE) # Remove https://
url <- glue::glue("{baseurl}/{course_page}{course}/?iframe={baseurl2}/{course_page}{course}-{year}/{page}.html{anchor}")
paste0("[", label, "](", url, ")")
}
# ex.: course_link("diagnostic", 2, "outils-de-diagnostic-suite", "résumé-avec-summarysuite")
## 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() & assignment() 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' = !"{assign_url$A01Ia_markdownM}",
# 'S-BIOG-937-958-959' = !"{assign_url$A01Ia_markdownC}",
# 'late_mons' = !"{assign_url$A01Ia_markdownM}"),
# course.starts = c(
# 'S-BIOG-015' = !"{class1_start(mod, 'A01')}",
# 'S-BIOG-937-958-959' = NA, # Nondefined date, or just ignore it
# 'sdd1late' = !"{class2_start(mod, 'A01')}"),
# course.ends = c(
# 'S-BIOG-015' = !"{n3_end(mod, 'A01')}",
# 'sdd1late' = !"{n3_end(mod, 'A02')}"),
# 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("")
}
h5p <- function(id, name, toc = "",
icourse = if (as.integer(substring(id, 2, 3)) < 6L) !"{courses[1]}" else
!"{courses[2]}",
institution = !"{institutions[1]}", acad_year = !"{acad_year}",
term = if (as.integer(substring(id, 2, 3)) < 6L) !"{terms[1]}" else
!"{terms[2]}",
set = !"{sets[1]}", ...)
learnitdown::h5p(id, name = name, toc = toc, baseurl = learnitdown$baseurl,
toc.def = "Exercice H5P {id}",
h5p.img = "images/list-h5p.png",
h5p.link = paste(learnitdown$baseurl, "h5p", sep = "/"),
icourse = icourse, institution = institution, acad_year = acad_year,
term = term, set = set, ...)
launch_shiny <- function(url, toc = "", fun = paste(learnitdown$package,
"run_app", sep = "::"), app = sub("\\?.+$", "", basename(url)),
#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}`.*",
baseurl = !"{baseurl}",
icourse = if (as.integer(substring(app, 2, 3)) < 6L)
!"{courses[1]}" else !"{courses[2]}",
institution = !"{institutions[1]}", acad_year = !"{acad_year}",
term = if (as.integer(substring(app, 2, 3)) < 6L)
!"{terms[1]}" else !"{terms[2]}",
set = !"{sets[1]}", ...)
learnitdown::launch_shiny(url = url, toc = toc, imgdir = learnitdown$shiny_imgdir,
fun = fun, alt1 = alt1, alt2 = alt2, toc.def = "Application Shiny {app}",
baseurl = baseurl,
run.url = paste(learnitdown$baseurl, "/", learnitdown$rstudio, "?runrcode=", sep = ""),
app.img = "images/list-app.png",
app.link = paste(learnitdown$baseurl, "shiny_app", sep = "/"),
icourse = icourse, institution = institution, acad_year = acad_year,
term = term, set = set, ...)
launch_report <- function(module, course = "S-BIOG-015", 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",
icourse = if (as.integer(substring(id, 2, 3)) < 6L) !"{courses[1]}" else
!"{courses[2]}",
institution = !"{institutions[1]}", acad_year = !"{acad_year}",
term = if (as.integer(substring(id, 2, 3)) < 6L) !"{terms[1]}" else
!"{terms[2]}", set = !"{sets[1]}")
learnitdown::learnr(id = id, title = title, package = package, toc = toc,
text = text, toc.def = "Tutoriel {id}",
#rstudio.url = paste(learnitdown$baseurl, learnitdown$rstudio, sep = "/"),
connect.url = learnitdown$connecturl, tuto.img = "images/list-tuto.png",
tuto.link = paste(learnitdown$baseurl, "tutorial", sep = "/"),
icourse = icourse, institution = institution, acad_year = acad_year,
term = term, set = set)
# Note: use course.urls = c(`S-BIOG-015` = "classroom url1", `S-BIOG-937-` = "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", institution = !"{institutions[1]}",
acad_year = !"{acad_year}", term = "Q1", set = !"{sets[1]}",
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, institution = institution, acad_year = acad_year, term = term,
set = set, 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", institution = !"{institutions[1]}",
acad_year = !"{acad_year}", term = "Q1", set = !"{sets[1]}",
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, institution = institution, acad_year = acad_year, term = term,
set = set, 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", institution = !"{institutions[1]}",
acad_year = !"{acad_year}", term = "Q1", set = !"{sets[1]}",
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, institution = institution, acad_year = acad_year, term = term,
set = set, 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", institution = !"{institutions[1]}",
acad_year = !"{acad_year}", term = "Q1", set = !"{sets[1]}",
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, institution = institution, acad_year = acad_year, term = term,
set = set, 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(id, header = "", clear.it = TRUE, finalize = FALSE)
learnitdown::show_ex_toc(id = id, header = header, clear.it = clear.it,
finalize = finalize)
# 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")
# Format-dependent sections
is_html_output = function()
knitr::opts_knit$get("rmarkdown.pandoc.to") == "html"
is_pdf_output = function()
knitr::opts_knit$get("rmarkdown.pandoc.to") == "latex"