2024-05-02 13:31:21 +02:00
|
|
|
#' User input processing
|
|
|
|
#'
|
|
|
|
#' @param x input
|
|
|
|
#'
|
|
|
|
#' @return processed input
|
|
|
|
#' @export
|
2024-02-27 13:20:21 +01:00
|
|
|
process_user_input <- function(x) {
|
2018-06-23 04:24:34 +02:00
|
|
|
UseMethod("process_user_input", x)
|
|
|
|
}
|
|
|
|
|
2024-05-02 13:31:21 +02:00
|
|
|
#' User input processing default
|
|
|
|
#'
|
|
|
|
#' @param x input
|
|
|
|
#' @param ... ignored
|
|
|
|
#'
|
|
|
|
#' @return processed input
|
|
|
|
#' @export
|
2018-06-23 04:24:34 +02:00
|
|
|
process_user_input.default <- function(x, ...) {
|
|
|
|
stop(
|
|
|
|
deparse(substitute(x)),
|
|
|
|
" must be a 'data.frame',",
|
|
|
|
" a 'response',",
|
|
|
|
" or a 'character' vector containing JSON.",
|
|
|
|
call. = FALSE
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-05-02 13:31:21 +02:00
|
|
|
|
|
|
|
#' User input processing data.frame
|
|
|
|
#'
|
|
|
|
#' @param x input
|
|
|
|
#' @param ... ignored
|
|
|
|
#'
|
|
|
|
#' @return processed input
|
|
|
|
#' @export
|
2018-06-23 04:24:34 +02:00
|
|
|
process_user_input.data.frame <- function(x, ...) {
|
2019-07-29 18:30:52 +02:00
|
|
|
x
|
2018-06-23 04:24:34 +02:00
|
|
|
}
|
|
|
|
|
2024-05-02 13:31:21 +02:00
|
|
|
#' User input processing character
|
|
|
|
#'
|
|
|
|
#' @param x input
|
|
|
|
#' @param ... ignored
|
|
|
|
#'
|
|
|
|
#' @return processed input
|
|
|
|
#' @export
|
2018-06-23 04:24:34 +02:00
|
|
|
process_user_input.character <- function(x, ...) {
|
|
|
|
if (!requireNamespace("jsonlite", quietly = TRUE)) {
|
|
|
|
stop(
|
|
|
|
"The package 'jsonlite' is needed to convert ",
|
|
|
|
deparse(substitute(x)),
|
|
|
|
" into a data frame.",
|
|
|
|
"\n Either install 'jsonlite' or pass ",
|
|
|
|
deparse(substitute(x)),
|
|
|
|
" as a 'data.frame'.",
|
|
|
|
call. = FALSE
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
jsonlite::fromJSON(x)
|
|
|
|
}
|
|
|
|
|
2024-05-02 13:31:21 +02:00
|
|
|
|
|
|
|
#' User input processing response
|
|
|
|
#'
|
|
|
|
#' @param x input
|
|
|
|
#' @param ... ignored
|
|
|
|
#'
|
|
|
|
#' @return processed input
|
|
|
|
#' @export
|
2018-06-23 04:24:34 +02:00
|
|
|
process_user_input.response <- function(x, ...) {
|
2018-06-23 04:34:35 +02:00
|
|
|
process_user_input(rawToChar(x$content))
|
2018-06-23 04:24:34 +02:00
|
|
|
}
|