I'm trying to make my code ask me for a "TRUE" or "FALSE" value before proceeding.
It currently works fine if I run it one line at a time, however when I run all the code at once in RStudio it simply proceeds without waiting for user input and records a value of "" for my parameter.
raw <- readline("TRUE or FALSE -- this is a validation run: ")
if (raw == "F" | raw == "FALSE" | raw == "False"){
validation <- F
} else{
validation <- T
}
rm(raw)
Ideally, I would like an answer that works regardless of how I run it -- RScript
, source
within RStudio, or running it (i.e. selecting the code and pressing run
or ctrl-enter).
if (toupper(unlist(strsplit(raw, ''))[1]) == 'F')
readline
is only for use in interactive mode.readLines
then?readLines
is not set up for a prompt. You need to describe how this will be used. Using Rscript is different than interactive use. You need to answer the first comment question. If you are "in RStudio", then most people would assume its for interactive console use. Just don't assume you can use it with Rscript or running from a system command line.