Skip to content

Commit 5e943af

Browse files
committedApr 16, 2024
feat: add function to validate agendas
A new function `validate_agenda` has been implemented to check the validity of an entire agenda. This function ensures that the agenda is a non-empty list and that each element of the list is a valid agenda item. It also supports loading the agenda from a file path if provided. The function will be useful for users to validate their agenda data structures before proceeding with further processing.
1 parent 159335d commit 5e943af

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
 

‎R/validation.R

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,59 @@ validate_agenda_element <- function(
8181
is_valid
8282
}
8383

84+
85+
#' Validates an agenda
86+
#'
87+
#' Checks if the agenda is a list (or a file path to a list) and if it is not
88+
#' empty and if all its elements are valid.
89+
#'
90+
#' @param agenda A list containing the agenda or a file path to it.
91+
#' @param ... Additional arguments to be passed to `validate_agenda_element`.
92+
#'
93+
#' @return A boolean indicating whether the agenda is valid.
94+
#'
95+
#' @export
96+
#'
97+
#' @examples
98+
#' validate_agenda(list(
99+
#' list(
100+
#' session = "Session 1",
101+
#' title = "Opening Session",
102+
#' speakers = "John Doe",
103+
#' moderators = "Jane Doe",
104+
#' type = "conference talk",
105+
#' from = "09:00 AM",
106+
#' to = "10:00 AM"
107+
#' ),
108+
#' list()
109+
#' ), session = TRUE, title = TRUE, speakers = TRUE, moderators = TRUE,
110+
#' type = TRUE, from = TRUE, to = TRUE)
111+
#' #> [1] FALSE # Because the second element is empty
112+
#'
113+
validate_agenda <- function(
114+
agenda,
115+
...
116+
) {
117+
118+
# Check if the agenda is a file path
119+
if (!purrr::is_empty(agenda) && is.character(agenda) && file.exists(agenda)){
120+
agenda <- dget(agenda)
121+
}
122+
123+
# Check if the agenda is a list
124+
if (!is.list(agenda)) {
125+
return(FALSE)
126+
}
127+
128+
# Check if the agenda is empty
129+
if (length(agenda) == 0) {
130+
return(FALSE)
131+
}
132+
133+
# Check if the agenda elements are valid
134+
purrr::map_lgl(agenda, ~ validate_agenda_element(.x, ...)) |> all()
135+
}
136+
84137
#' Validate summary tree id consistency
85138
#'
86139
#' @param summary_tree A list containing the summary tree or a file path to it.

0 commit comments

Comments
 (0)