User inputs

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

User inputs

chrisli1223
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? (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? Many thanks, Chris
Reply | Threaded
Open this post in threaded view
|

Re: User inputs

Dieter Menne
chrisli1223 wrote
(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?
Depends on how you run the script. Try to insert
print(interactive())

If the result is FALSE, it does not wait. Have you tried a simple

a = readline()

in your GUI? What happens?


Dieter
Reply | Threaded
Open this post in threaded view
|

Re: User inputs

Don MacQueen
In reply to this post by chrisli1223
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]]
>
>______________________________________________
>[hidden email] 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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: User inputs

chrisli1223
In reply to this post by chrisli1223
Thank you very much Dieter and Don. This solves my problem. :)