[R] User inputs

Don MacQueen macq at llnl.gov
Thu Apr 22 02:18:38 CEST 2010


At 4:24 PM -0800 4/20/10, chrisli1223 wrote:
>Hi everyone,
>
>I have been searching for answers for the following questions but I don't
>have much success. The following questions may actually be quite simple. Any
>help would be greatly appreciated.
>
>(1) I have written a script which requires user input. I am using the
>readline() command.However, everytime when I run the script, R does not wait
>for the user input and proceed to the next line. Is there something like
>par(ask=T) to solve this problem?
>
>(2) In my script, I want it to stop running when a certain condition is met.
>I have tried using the stop() function, but apparently R only stops reading
>that line and start reading the following lines. I have also thought about
>quit() but it is not quite what I want. May someone please lead me to the
>right function please?

Use  if()

## beginning of script

## various R that always run

if ( condition is met) {
   ## here is where we stop
   cat('My condition is met, I am stopping\n')
} else {
   cat('My condition is not met, I am continuing\n')
   ## put here all the commands that should run when the condition is not met
}


>(3) When a minor error happens, I would like to get the user permission by
>pressing the return key before the script continues to run. What function
>should I be looking at?

Use the
   try()
function to control what happens when an error happens

>
>Many thanks,
>Chris
>--
>View this message in context: 
>http://*n4.nabble.com/User-inputs-tp2018251p2018251.html
>Sent from the R help mailing list archive at Nabble.com.
>
>	[[alternative HTML version deleted]]
>
>______________________________________________
>R-help at r-project.org mailing list
>https://*stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://*www.*R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.


-- 
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062



More information about the R-help mailing list