Added inputdlg homonymous
This commit is contained in:
parent
32e57e4de4
commit
ac05f90b87
3 changed files with 36 additions and 0 deletions
17
R/inputdlg.R
Normal file
17
R/inputdlg.R
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#' @title Gather user input
|
||||
#' @description Replicates the functionality of the homonymous function in Matlab (sans dialog box)
|
||||
#' @param prompt Text field with user instructions
|
||||
#' @param dim number of dimensions in the answwers
|
||||
#' @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)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue