-
Notifications
You must be signed in to change notification settings - Fork 4
/
types.castList.R
55 lines (41 loc) · 1.4 KB
/
types.castList.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
#' @title Cast list
#' @description cast list
#' @param format no options (other than the default)
#' @param value lists, or valid JSON format arrays to cast
#' @rdname types.castList
#' @export
#'
#' @seealso \href{https://specs.frictionlessdata.io//table-schema/#array}{Types and formats specifications}
#'
#' @examples
#'
#' types.castList(format = "default", value = list())
#'
#' types.castList(format = "default", value = list('key', 'value'))
#'
#' types.castList(format = "default", value = '["key", "value"]') # cast valid json array
#'
types.castList <- function(format, value) {
if (!is.list(value)) {
if (!is.character(value)) {
return(config::get("ERROR", file = system.file("config/config.yml", package = "tableschema.r")))
}
}
if (is.list(value)) {
return(value)
} else if (isTRUE(jsonlite::validate(value))) {
value <- tryCatch({
helpers.from.json.to.list(value)
},
warning = function(w) {
return(config::get("ERROR", file = system.file("config/config.yml", package = "tableschema.r")))
},
error = function(e) {
return(config::get("ERROR", file = system.file("config/config.yml", package = "tableschema.r")))
},
finally = {
})
}
if (!is.list(value) ) return(config::get("ERROR", file = system.file("config/config.yml", package = "tableschema.r")))
return(value)
}