ourMELONS/R/inputdlg.R

17 lines
677 B
R
Raw Normal View History

2020-03-18 08:27:21 +01:00
#' @title Gather user input
#' @description Replicates the functionality of the homonymous function in Matlab (sans dialog box)
#' @param prompt Text field with user instructions
2020-03-18 15:02:38 +01:00
#' @param dims number of dimensions in the answwers
2020-03-18 08:27:21 +01:00
#' @param definput default value of the input
#' @export
inputdlg <- function(prompt, definput=NULL, dims=1) {
if (!is.null(definput)) {
prompt <- append(prompt, paste0(" (default: ", definput, ")"))
}
input_chr <- readline(paste0(prompt, ": "))
if (input_chr == "") input_chr <- definput
input_chr_or_num <- tryCatch(
as.numeric(input_chr), warning = function(w) input_chr
)
return(input_chr_or_num)
}