[R] 'scan' in a script?

jim holtman jholtman at gmail.com
Fri Jul 10 13:58:50 CEST 2009


I have no problem running a script that uses readline when the script
is 'source'd in.  If you are going a cut/paste to the console, then it
is using the standard input and readline (or any other input that you
would expect to be able to enter from the console) will start reading
your source.  Here is an example:
I have a script consisting of:

x <- readline("Input your data:")
print(x)


I first cut/paste it


> # this is the cut/paste
> x <- readline("Input your data:")
Input your data:print(x)     <<<<== notice it read the next command
>
> x  # output 'x';  entered at the console; look at what is output
[1] "print(x)"

# now 'source' it
> source(file('clipboard'))
Input your data:my input data
[1] "my input data"
>

Notice that the above did print the input I entered "my input data"


So determine how you are invoking your script.  You should be using 'source'


On Fri, Jul 10, 2009 at 12:35 AM, Mark Knecht<markknecht at gmail.com> wrote:
> On Thu, Jul 9, 2009 at 6:05 PM, jim holtman<jholtman at gmail.com> wrote:
>> If you want the value printed in the script, then use the 'print' function:
>>
>> print(MyNames)
>>
>> There is an implicit 'print' when you type an object's name at the
>> command line, but with you have it within a script, you have to
>> explicitly print it.
>>
> <SNIP>
>
> That's good to know in terms of reliably getting the data out but my
> bigger problem right now is it doesn't wait for me to type any input
> and therefore my program (running as a script) doesn't know what to
> do.
>
> I guess this must be me doing somethign jsut plain wrong. I figured
> I'd ask and get an answer in 30 seconds. Strange I'm that far off. If
> I need to run it in the interpreter instead of source it then for now
> I can do that until I learn what I'm doing wrong.
>
> I've got more interesting questions of which the answers are far more
> important to me than this one!
>
> Thanks,
> Mark
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?




More information about the R-help mailing list