-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathexcel-messages.R
60 lines (55 loc) · 1.82 KB
/
excel-messages.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
#' @title ExcelMessaging
#' @description R6 class for tracking and printing messages for the Excel template
#' @field type "warnings" or "errors" (could potentially include other kind of information)
#' @field messages list of messages included in each script section
#' @importFrom ospsuite.utils %||%
#' @keywords internal
ExcelMessaging <- R6::R6Class(
"ExcelMessaging",
cloneable = FALSE,
public = list(
type = NULL,
messages = NULL,
#' @description Initialize an `ExcelMessaging` object
#' @param type "warnings" or "errors"
#' @return A new `ExcelMessaging` object
initialize = function(type) {
validateIsIncluded(type, c("errors", "warnings"))
self$type <- type
self$messages <- list()
},
#' @description display the messages stored in messages
#' @return Messages content
displayMessage = function() {
message <- NULL
for (sectionIndex in seq_along(self$messages)) {
if (isEmpty(self$messages[[sectionIndex]])) {
next
}
message <- c(
message,
self$getMessageHeader(names(self$messages)[sectionIndex]),
paste("- ", self$messages[[sectionIndex]])
)
}
if (isEmpty(message)) {
logInfo(self$getNoIssueMessage())
return(invisible())
}
logError(message)
return(invisible(message))
},
#' @description Get message header
#' @param section name of R script section
getMessageHeader = function(section) {
return(paste(
"Potential", highlight(self$type),
"identified when writing section ", highlight(section)
))
},
#' @description Get message displaying no issue identified
getNoIssueMessage = function() {
return(paste("No potential", highlight(self$type), "identified when writing R script"))
}
)
)