forked from OHDSI/CohortGenerator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathR6ClassFunctions.R
99 lines (81 loc) · 2.81 KB
/
R6ClassFunctions.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
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
.getAssertChoices <- function(category) {
readr::read_csv(file = system.file(package = pkgload::pkg_name(), "csv", "assertChoices.csv"), show_col_types = FALSE) |>
dplyr::filter(category == !!category) |>
dplyr::pull(choice)
}
.getCaseSql <- function(covariateValues,
then) {
sql <- glue::glue("when covariate_value >= {thresholdMin} and covariate_value <= {thresholdMax} then {covariateId}")
caseSql <- glue::glue("case {sql} end as covariate_id", sql = paste(caseSql, collapse = "\n"))
}
.setString <- function(private, key, value, naOk = FALSE) {
checkmate::assert_string(x = value, na.ok = naOk, min.chars = 1, null.ok = FALSE)
private[[key]] <- value
invisible(private)
}
.setCharacter <- function(private, key, value) {
checkmate::assert_character(x = value, min.chars = 1, null.ok = FALSE)
private[[key]] <- value
invisible(private)
}
.setNumber <- function(private, key, value, nullable = FALSE) {
checkmate::assert_numeric(x = value, null.ok = nullable)
private[[key]] <- value
invisible(private)
}
.setInteger <- function(private, key, value, nullable = FALSE) {
checkmate::assert_integer(x = value, null.ok = nullable)
private[[key]] <- value
invisible(private)
}
.setLogical <- function(private, key, value) {
checkmate::assert_logical(x = value, null.ok = FALSE)
private[[key]] <- value
invisible(private)
}
.setClass <- function(private, key, value, class, nullable = FALSE) {
checkmate::assert_class(x = value, classes = class, null.ok = nullable)
private[[key]] <- value
invisible(private)
}
.setListofClasses <- function(private, key, value, classes) {
checkmate::assert_list(x = value, types = classes, null.ok = FALSE, min.len = 1)
private[[key]] <- value
invisible(private)
}
.setChoice <- function(private, key, value, choices) {
checkmate::assert_choice(x = value, choices = choices, null.ok = FALSE)
private[[key]] <- value
invisible(private)
}
.setChoiceList <- function(private, key, value, choices) {
checkmate::assert_subset(x = value, choices = choices, empty.ok = FALSE)
private[[key]] <- value
invisible(private)
}
.setActiveLogical <- function(private, key, value) {
# return the value if nothing added
if(missing(value)) {
vv <- private[[key]]
return(vv)
}
# replace the codesetTempTable
.setLogical(private = private, key = key, value = value)
}
.setActiveString <- function(private, key, value) {
# return the value if nothing added
if(missing(value)) {
vv <- private[[key]]
return(vv)
}
# replace the codesetTempTable
.setString(private = private, key = key, value = value)
}
.setActiveInteger <- function(private, key, value) {
# return the value if nothing added
if(missing(value)) {
vv <- private[[key]]
return(vv)
}
.setInteger(private = private, key = key, value = value)
}