[R] using scan to record user's input
Ken Knoblauch
knoblauch at lyon.inserm.fr
Sun Mar 11 20:17:10 CET 2007
No, it's a good question. I was using the apple-return feature of the editor
on the R.app from Mac. Is that more like sourcing or copy and pasting?
I was planning eventually to source the file or put the code in a function.
I'll try it on a PPC Mac later and see if it works there. Thanks.
best,
Ken
Patrick Callier wrote:
> Silly question: Are you 'source'-ing this code or copying and pasting
> it from somewhere? I don't have any problems running your above
> example on a PPC Mac with almost the same version of R (using
> 'source').
>
> Here's my info:
> R version 2.4.1 (2006-12-18)
> powerpc-apple-darwin8.8.0
>
> locale:
> en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>
> attached base packages:
> [1] "stats" "graphics" "grDevices" "utils" "datasets"
> "methods" "base"
>
> other attached packages:
> MASS KernSmooth
> "7.2-30" "2.22-19"
>
> Otherwise, I'm as stumped as you are.
>
> On 3/11/07, Ken Knoblauch <knoblauch at lyon.inserm.fr> wrote:
>> I'm using scan in a script to record a series of responses of the user
>> as
>> a function
>> of some graphs that I put up on the screen. A toy version would be,
>>
>> y <- rep(NA, 3)
>> for (ix in seq( length(y) ) ) {
>> y[ix] <- scan( n = 1 )
>> }
>>
>> However, if I include any code after this loop, for example,
>> y <- rep(NA, 3)
>> for (ix in seq( length(y) ) ) {
>> y[ix] <- scan( n = 1 )
>> }
>> y
>>
>> I get an error after I've entered my first number.
>>
>> 1: y
>> 1: 3
>> Error in scan(file, what, nmax, sep, dec, quote, skip, nlines,
>> na.strings, :
>> scan() expected 'a real', got 'y'
>>
>> scan seems to be trying to read the commands after the loop. In the
>> real
>> case,
>> the loop is longer and there are more commands after the loop.
>> If I have more commands, I get the error right away, before the prompt
>> to
>> enter a number.
>>
>> I didn't see anything in the scan help that would allow me to circumvent
>> this error.
>>
>> Can anyone suggest a way to get around this error.
>>
>> Thank you.
>>
>> Ken
>>
>> Here is my info
>>
>> sessionInfo()
>> R version 2.4.1 Patched (2007-01-23 r40561)
>> i386-apple-darwin8.8.1
>>
>> locale:
>> C
>>
>> attached base packages:
>> [1] "stats" "graphics" "grDevices" "utils" "datasets"
>> "methods"
>> [7] "base"
>>
>> other attached packages:
>> MASS
>> "7.2-31"
>>
>>
>> --
>> Ken Knoblauch
>> Inserm U846
>> Institut Cellule Souche et Cerveau
>> Département Neurosciences Intégratives
>> 18 avenue du Doyen Lépine
>> 69500 Bron
>> France
>> tel: +33 (0)4 72 91 34 77
>> fax: +33 (0)4 72 91 34 61
>> portable: +33 (0)6 84 10 64 10
>> http://www.pizzerialesgemeaux.com/u846/
>>
>> ______________________________________________
>> R-help at stat.math.ethz.ch 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.
>>
>
--
Ken Knoblauch
Inserm U846
Institut Cellule Souche et Cerveau
Département Neurosciences Intégratives
18 avenue du Doyen Lépine
69500 Bron
France
tel: +33 (0)4 72 91 34 77
fax: +33 (0)4 72 91 34 61
portable: +33 (0)6 84 10 64 10
http://www.pizzerialesgemeaux.com/u846/
More information about the R-help
mailing list