-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathvalidate_read_cell_part_object.R
87 lines (81 loc) · 2.27 KB
/
validate_read_cell_part_object.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
validate_read_cell_part_object <- function(x, level) {
stage <- attr(x, "read_cells_stage")
if (missing(level)) {
level <- stage
}
if (is.null(level)) {
abort("read_cell_part object is not valid")
}
if (length(level) != 1) {
abort("read_cell_part object is not valid")
}
if (is.numeric(level)) {
level <- as.integer(level)
if (level >= 1 & level <= length(read_cell_task_orders)) {
level <- read_cell_task_orders[level]
}
}
if (is.character(level)) {
if (level %in% read_cell_task_orders) {
if (level == read_cell_task_orders[1]) {
# NULL is possible
if (is.null(x)) {
return(list(chk = TRUE, level = level))
}
# a df
if (is.data.frame(x)) {
if (nrow(x) > 0) {
return(list(chk = TRUE, level = level))
}
}
# list of dfs
if (is.list(x)) {
if (length(x) > 0) {
if (is.data.frame(x[[1]])) {
return(list(chk = TRUE, level = level))
}
}
}
}
if (level == read_cell_task_orders[2]) {
if (is.list(x)) {
if (length(x) > 0) {
if (x %>% map_lgl(is_cell_df) %>% all()) {
return(list(chk = TRUE, level = level))
}
}
}
}
if (level == read_cell_task_orders[3]) {
if (is.list(x)) {
if (length(x) > 0) {
if (x %>% map_lgl(is_cell_df) %>% all()) {
if (x %>% map_lgl(~ hasName(.x, "type")) %>% all()) {
return(list(chk = TRUE, level = level))
}
}
}
}
}
if (level == read_cell_task_orders[4]) {
if (is.list(x)) {
if (length(x) > 0) {
if (x %>% map_lgl(~ inherits(.x, cell_df_analysis_class[1])) %>% all()) {
return(list(chk = TRUE, level = level))
}
}
}
}
if (level == read_cell_task_orders[5]) {
if (is.data.frame(x)) {
if (all(utils::hasName(x, setdiff(defcols, "table_tag")))) {
return(list(chk = TRUE, level = level))
}
}
}
} else {
abort(paste0(level, " is not a valid level."))
}
}
return(list(chk = FALSE, level = level))
}