[R] R interactive input like C++

Paul Hiemstra p.hiemstra at geo.uu.nl
Thu Apr 15 09:44:05 CEST 2010


余舟 wrote:
> Huhu,
>
> Thank you for all you guys. readline works.
>
> I hope R can be more and more powerful to deal with strings.
>   
Strings and power come from regular expressions, check out ?regexpr.

cheers,
Paul
> Thank you so much;
> Zhou
>
> 2010/4/14 Erik Iverson <eriki at ccbr.umn.edu>
>
>   
>> David Scott wrote:
>>
>>     
>>> Erik Iverson wrote:
>>>
>>>       
>>>> ?? wrote:
>>>>
>>>>         
>>>>> Thank you for your reply.
>>>>>
>>>>> My objective is simple. Assume  I have a constant vector, say Vector. in
>>>>> C++ code, I want to do:
>>>>>
>>>>>
>>>>> int index;
>>>>> cout<<"Please enter the index of the element you want to look at Vector
>>>>> :";
>>>>> cin>>index
>>>>> cout<<Vector[index]
>>>>>
>>>>>
>>>>> I want every user to be able to do this.
>>>>>
>>>>> As I understand, scan can only read data from a fixed file. Can I just
>>>>> get the input from the shell directly?
>>>>>
>>>>>
>>>>>           
>>>> Isn't that what the file argument of ?scan says?  I think?
>>>>
>>>>     file: the name of a file to read data values from.  If the
>>>>           specified file is ‘""’, then input is taken from the keyboard
>>>>           (or whatever ‘stdin()’ reads if input is redirected or R is
>>>>           embedded).
>>>>
>>>>
>>>>         
>>> I think the required function is readline which prompts for user input.
>>>
>>> ?readline
>>>
>>>
>>>       
>> Great, didn't know that one.  The example in ?readline is hilarious.
>>
>>     
>
> 	[[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.
>   


-- 
Drs. Paul Hiemstra
Department of Physical Geography
Faculty of Geosciences
University of Utrecht
Heidelberglaan 2
P.O. Box 80.115
3508 TC Utrecht
Phone:  +3130 274 3113 Mon-Tue
Phone:  +3130 253 5773 Wed-Fri
http://intamap.geo.uu.nl/~paul
http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770



More information about the R-help mailing list