|
11 | 11 | setup = fromJSON(txt = content)$setups$setup |
12 | 12 | sid = data.frame(join_id = 1:length(setup$setup_id), setup_id = setup$setup_id) |
13 | 13 |
|
14 | | - # Get parameters and clean them up |
15 | | - param = setup$parameter |
16 | | - if (!is.null(names(param))) { |
17 | | - # if elements have a name, it refers to parameter |
18 | | - param = param[!vlapply(param, function(x) length(x) == 0)] |
19 | | - param = as.data.frame(param, stringsAsFactors = FALSE) |
20 | | - param = cbind(param, join_id = 1, stringsAsFactors = FALSE) |
21 | | - } else { |
22 | | - # add names |
23 | | - param = setNames(param, 1:length(param)) |
24 | | - # filter out NULL or empty elements |
25 | | - param = param[!vlapply(param, function(x) length(x) == 0)] |
26 | | - # inside each element, replace empty values with NA |
27 | | - param = lapply(param, function(x) { |
28 | | - replace(x, which(vlapply(x, function(i) length(i) == 0)), NA_character_) |
29 | | - }) |
30 | | - param = rbindlist(param, fill = TRUE, idcol = "join_id") |
31 | | - param = as.data.frame(param, stringsAsFactors = FALSE) |
32 | | - } |
33 | | - |
34 | | - list.cols = colnames(param)[vlapply(param, is.list)] |
35 | | - for (col in list.cols) { |
36 | | - ind = which(vlapply(param[[col]], function(i) length(i) == 0)) |
37 | | - param[[col]][ind] = NA_character_ |
38 | | - param[[col]] = unlist(param[[col]], recursive = FALSE) |
39 | | - } |
| 14 | + param = cleanupSetupParameters(setup$parameter) |
40 | 15 |
|
41 | 16 | ret = merge(param, sid) |
42 | 17 | ret$id = ret$join_id = NULL |
|
66 | 41 | #' @export |
67 | 42 | #' @example inst/examples/listOMLSetup.R |
68 | 43 | listOMLSetup = memoise(.listOMLSetup) |
| 44 | + |
| 45 | + |
| 46 | +# Get parameters and clean them up |
| 47 | +cleanupSetupParameters = function(param) { |
| 48 | + if (!is.null(names(param))) { |
| 49 | + # if elements have a name, it refers to parameter |
| 50 | + param = param[!vlapply(param, function(x) length(x) == 0)] |
| 51 | + param = as.data.frame(param, stringsAsFactors = FALSE) |
| 52 | + param = cbind(param, join_id = 1, stringsAsFactors = FALSE) |
| 53 | + } else { |
| 54 | + # add names |
| 55 | + param = setNames(param, 1:length(param)) |
| 56 | + # filter out NULL or empty elements |
| 57 | + param = param[!vlapply(param, function(x) length(x) == 0)] |
| 58 | + # inside each element, replace empty values with NA |
| 59 | + param = lapply(param, function(x) { |
| 60 | + replace(x, which(vlapply(x, function(i) length(i) == 0)), NA_character_) |
| 61 | + }) |
| 62 | + param = rbindlist(param, fill = TRUE, idcol = "join_id") |
| 63 | + param = as.data.frame(param, stringsAsFactors = FALSE) |
| 64 | + } |
| 65 | + |
| 66 | + list.cols = colnames(param)[vlapply(param, is.list)] |
| 67 | + for (col in list.cols) { |
| 68 | + ind = which(vlapply(param[[col]], function(i) length(i) == 0)) |
| 69 | + param[[col]][ind] = NA_character_ |
| 70 | + param[[col]] = unlist(param[[col]], recursive = FALSE) |
| 71 | + } |
| 72 | + return(param) |
| 73 | +} |
0 commit comments