-
Notifications
You must be signed in to change notification settings - Fork 4
/
learnr_bugfix.R
57 lines (47 loc) · 1.77 KB
/
learnr_bugfix.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
# avoid cryptic warning in exercises:
invisible_feedback <- function() {
NULL
}
# load dep functions ino enviroment:
# return feedback as html
feedback_as_html <- function(feedback) {
if (is.null(feedback$type) || identical(feedback$type, "auto"))
feedback$type <- ifelse(feedback$correct, "success", "error")
if (feedback$type == "custom") {
div(feedback$message)
}
else if (feedback$type %in% c("success", "info", "warning", "error")) {
if (feedback$type == "error")
feedback$type <- "danger"
div(class = paste0("alert alert-", feedback$type),
role = "alert",
feedback$message
)
}
else {
stop("Invalid message type specified.", call. = FALSE)
}
}
# return feedback if it's valid, otherwise throw an error
feedback_validated <- function(feedback) {
if (is.null(feedback))
return(feedback)
if (!is.character(feedback$message))
stop("Feedback must include a 'message' character vector", call. = FALSE)
if (!is.logical(feedback$correct))
stop("Feedback must include a 'correct' logical value", call. = FALSE)
feedback_types <- c("auto", "success", "info", "warning", "error", "custom")
if (is.null(feedback$type))
feedback$type <- "auto"
if (!feedback$type %in% feedback_types)
stop("Feedback 'type' field must be one of these values: ",
paste(feedback_types, collapse = ", "), call. = FALSE)
feedback_locations <- c("append", "prepend", "replace")
if (is.null(feedback$location))
feedback$location <- "append"
if (!feedback$location %in% feedback_locations)
stop("Feedback 'location' field must be one of these values: ",
paste(feedback_locations, collapse = ", "), call. = FALSE)
feedback
}
assignInNamespace("invisible_feedback",invisible_feedback,ns="learnr")