[R] 'scan' in a script?

Mark Knecht markknecht at gmail.com
Thu Jul 9 23:08:04 CEST 2009


Jim,
   In Rgui there is a feature to create a new script so I open that
and get a blank editor. I put these commands in the script

MyNames = scan(what="")
MyNames

   Whether I ask Rgui to run the whole script as a script - not
sourced - it runs the first command, doesn't wait for input and then
runs the second command. I see

> MyNames
character(0)
>

   If I right click the first line and ask it to run the selection or
line then R waits for the input.

   If I source the file then the opposite happens. It does the scan
correctly, waiting for me to make entries. When I finish it doesn't
print what's in MyNames, as shown here where I typed in happy sad test
go and hit enter.

> source("C:\\Users\\Mark\\Documents\\R\\Test Cases\\scan from script.R")
1: happy sad test go
5:
Read 4 items
>

   Possibly (probably!) this is a misunderstanding on my part, but
it's something I need to start looking at as the reason for me
checking out R at all was as a potential way to develop a complete
program, as opposed to writing it in C, so I need to start looking at
how to give it input (file names, directory paths, user requests)
other than changing source code.

   I hope this is clear enough and I appreciate your inputs.

Cheers,
Mark

On Thu, Jul 9, 2009 at 1:02 PM, jim holtman<jholtman at gmail.com> wrote:
> Exactly how are you using it?  How you executing your script?  Are you
> using cut/paste or source?  Have you tried 'readline'?
>
> More details on what you mean by it does not work as expected.
>
> On Thu, Jul 9, 2009 at 2:24 PM, Mark Knecht<markknecht at gmail.com> wrote:
>> When I use the scan function in the Rgui console it works as expected.
>> However it seems that when I put the same command in a script file it
>> doesn't wait for input.
>>
>> Is there an option to scan to make it wait for input when used in a
>> script? Or is there possibly a different function that will do in a
>> script the same sort of thing as scan does in the console?
>>
>> Thanks,
>> Mark
>>
>> ______________________________________________
>> 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.
>>
>
>
>
> --
> 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