Pause the execution of a function

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Pause the execution of a function

Lisa
Dear all,

I am trying to write a script to pause the execution of a function and provide some additional commands to the function and then continue execution of the function. For example, when my function detects a wrong number in a dataset, the function pauses automatically and returns information on the screen:

“There is a wrong number in the dataset. Would you like to correct it? ”

If I input “yes” from the keyboard and hit the enter key, the function asks again:

“What is the correct number?”

After inputting a correct number from the keyboard and hitting the enter key, the function continues to execute.

Can anybody please help how to get this done? Thanks a lot in advance

Lisa
Reply | Threaded
Open this post in threaded view
|

Re: Pause the execution of a function

Jonathan Daily
Try ?scan or ?readLines.

On Wed, Apr 27, 2011 at 11:42 AM, Lisa <[hidden email]> wrote:

> Dear all,
>
> I am trying to write a script to pause the execution of a function and
> provide some additional commands to the function and then continue execution
> of the function. For example, when my function detects a wrong number in a
> dataset, the function pauses automatically and returns information on the
> screen:
>
> “There is a wrong number in the dataset. Would you like to correct it? ”
>
> If I input “yes” from the keyboard and hit the enter key, the function asks
> again:
>
> “What is the correct number?”
>
> After inputting a correct number from the keyboard and hitting the enter
> key, the function continues to execute.
>
> Can anybody please help how to get this done? Thanks a lot in advance
>
> Lisa
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Pause-the-execution-of-a-function-tp3478535p3478535.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [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.
>



--
===============================================
Jon Daily
Technician
===============================================
#!/usr/bin/env outside
# It's great, trust me.

______________________________________________
[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: Pause the execution of a function

Lisa
Thanks. I will try them.
Reply | Threaded
Open this post in threaded view
|

Re: Pause the execution of a function

Rolf Turner-3
In reply to this post by Jonathan Daily
On 28/04/11 06:09, Jonathan Daily wrote:
> Try ?scan or ?readLines.

I think she might actually want readline() rather than either of the above.

     cheers,

         Rolf Turner

> On Wed, Apr 27, 2011 at 11:42 AM, Lisa<[hidden email]>  wrote:
>> Dear all,
>>
>> I am trying to write a script to pause the execution of a function and
>> provide some additional commands to the function and then continue execution
>> of the function. For example, when my function detects a wrong number in a
>> dataset, the function pauses automatically and returns information on the
>> screen:
>>
>> “There is a wrong number in the dataset. Would you like to correct it? ”
>>
>> If I input “yes” from the keyboard and hit the enter key, the function asks
>> again:
>>
>> “What is the correct number?”
>>
>> After inputting a correct number from the keyboard and hitting the enter
>> key, the function continues to execute.
>>
>> Can anybody please help how to get this done? Thanks a lot in advance
>>
>> Lisa
>>
>>
>> --
>> View this message in context: http://r.789695.n4.nabble.com/Pause-the-execution-of-a-function-tp3478535p3478535.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> [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.
>>
>
>

______________________________________________
[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: Pause the execution of a function

Lisa
Hi, Rolf,

Thank you for your help. I am trying to use readline() and I have a question about the maximum length of prompt string. The R help on readline() says:

“The prompt string will be truncated to a maximum allowed length, normally 256 chars (but can be changed in the source code).”

I don’t know how to change the source code. Could you please help how to get this done? Thanks.

Lisa
Reply | Threaded
Open this post in threaded view
|

Re: Pause the execution of a function

Rolf Turner-3
On 29/04/11 08:56, Lisa wrote:

> Hi, Rolf,
>
> Thank you for your help. I am trying to use readline() and I have a question
> about the maximum length of prompt string. The R help on readline() says:
>
> “The prompt string will be truncated to a maximum allowed length, normally
> 256 chars (but can be changed in the source code).”
>
> I don’t know how to change the source code. Could you please help how to get
> this done? Thanks.

Well, if you don't know how to change the source code, don't mess with
it.  It's not exactly simple.

Why on earth would you want a prompt string longer than 256 characters
anyway?  It seems to me that you need to think more carefully and clearly
about what you are trying to do.

If you want to give lengthy instructions (lengthy instructions  are probably
a bad idea, but that's another matter) to users about what to key in as
input,
use cat() prior to the invocation of readline().

     cheers,

             Rolf Turner

______________________________________________
[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.