|
| 1 | +#' Valid inputs |
| 2 | +#' |
| 3 | +#' Get a list of valid input_items for a context. |
| 4 | +#' |
| 5 | +#' @param context The name of a valid context (character) |
| 6 | +#' @return A list of input item names for a context |
| 7 | +#' @examples |
| 8 | +#' # list of input items for the "study" context |
| 9 | +#' context_inputs("study") |
| 10 | +#' @export |
| 11 | +context_inputs = function(context) { |
| 12 | + if (!is.character(context)) { |
| 13 | + stop('"context" must be of type "character"') |
| 14 | + } |
| 15 | + |
| 16 | + name_valid = context %in% names(metabolomicsWorkbenchR::context) |
| 17 | + if (!name_valid) { |
| 18 | + stop(paste0('"',context,'" is not a recognised context. Use ', |
| 19 | + 'names(context) for a list of valid contexts')) |
| 20 | + } |
| 21 | + |
| 22 | + return(metabolomicsWorkbenchR::context[[context]]$input_items) |
| 23 | +} |
| 24 | + |
| 25 | +#' Valid outputs |
| 26 | +#' |
| 27 | +#' Get a list of valid output_items for a context. |
| 28 | +#' |
| 29 | +#' @param context The name of a valid context (character) |
| 30 | +#' @return A list of output item names for a context |
| 31 | +#' @examples |
| 32 | +#' # list of output items for the "study" context |
| 33 | +#' context_outputs("study") |
| 34 | +#' @export |
| 35 | +context_outputs = function(context) { |
| 36 | + if (!is.character(context)) { |
| 37 | + stop('"context" must be of type "character"') |
| 38 | + } |
| 39 | + |
| 40 | + name_valid = context %in% names(metabolomicsWorkbenchR::context) |
| 41 | + if (!name_valid) { |
| 42 | + stop(paste0('"',context,'" is not a recognised context. Use ', |
| 43 | + 'names(context) for a list of valid contexts')) |
| 44 | + } |
| 45 | + |
| 46 | + x=metabolomicsWorkbenchR::context[[context]]$output_items |
| 47 | + w=which(x=='all') |
| 48 | + if (length(w)>0){ |
| 49 | + x=x[-w] |
| 50 | + } |
| 51 | + return(x) |
| 52 | +} |
| 53 | + |
| 54 | +#' Valid input_value for input_item |
| 55 | +#' |
| 56 | +#' Displays a valid input_value for an input_item and returns an example that |
| 57 | +#' matches the required input pattern. |
| 58 | +#' |
| 59 | +#' @param input_item The name of a valid input_item (character) |
| 60 | +#' @return An example input value matching the pattern required for the chosen |
| 61 | +#' input item. |
| 62 | +#' @examples |
| 63 | +#' # example input_value for input item "study_id" |
| 64 | +#' input_example('study_id') |
| 65 | +#' @export |
| 66 | +input_example = function(input_item) { |
| 67 | + if (!is.character(input_item)) { |
| 68 | + stop('"input_item" must be of type "character"') |
| 69 | + } |
| 70 | + |
| 71 | + name_valid = input_item %in% names(metabolomicsWorkbenchR::input_item) |
| 72 | + if (!name_valid) { |
| 73 | + stop(paste0('"',input_item,'" is not a recognised input_item. Use ', |
| 74 | + 'names(input_item) for a list of valid input items')) |
| 75 | + } |
| 76 | + |
| 77 | + show(metabolomicsWorkbenchR::input_item[[input_item]]) |
| 78 | + |
| 79 | + return( |
| 80 | + invisible(metabolomicsWorkbenchR::input_item[[input_item]]$example[1])) |
| 81 | +} |
| 82 | + |
| 83 | + |
0 commit comments