forked from HorridTom/autospc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathargument_validation.R
More file actions
59 lines (51 loc) · 1.46 KB
/
Copy pathargument_validation.R
File metadata and controls
59 lines (51 loc) · 1.46 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
#' Validate chart_type argument
#'
#' Checks that `chart_type` is a single, non-NULL character string corresponding
#' to a supported SPC chart type. Intended for internal use only.
#'
#' @param chart_type Character scalar specifying chart type.
#'
#' @return Invisibly returns TRUE if valid; otherwise errors.
#' @noRd
validate_chart_type <- function(chart_type) {
allowed_chart_types <- c("XMR", "MR", "C", "C'", "P", "P'")
# NULL check
if (is.null(chart_type)) {
lifecycle::deprecate_stop(
when = "0.0.0.9008",
what = I("chart_type = NULL"),
details = I(paste("Please explicitly pass the desired chart type.",
"Available chart types are: ",
paste(allowed_chart_types, collapse = ", "),
".")))
}
# Length check
if (length(chart_type) != 1) {
stop(
"chart_type must have length one. ",
"Available chart types are: ",
paste(allowed_chart_types, collapse = ", "),
".",
call. = FALSE
)
}
# Type check (defensive)
if (!is.character(chart_type)) {
stop(
"chart_type must be a character string.",
call. = FALSE
)
}
# Value check
if (!chart_type %in% allowed_chart_types) {
stop(
sprintf(
"Invalid chart_type: '%s'. Available chart types are: %s.",
chart_type,
paste(allowed_chart_types, collapse = ", ")
),
call. = FALSE
)
}
invisible(TRUE)
}