[R] R (Input from Keyboard): How do I remove error?

Petr Klasterecky klaster at karlin.mff.cuni.cz
Thu Mar 1 12:34:17 CET 2007


?readline
Note that this gives you a character vector, so you might want to use 
as.numeric() after that.

Petr

d. sarthi maheshwari napsal(a):
> Hi,
> 
> I am trying to read some value from keyboard in one of my R program. I want
> to do manipulation on data based on this value. But I am facing a problem
> which is described below with the help of an example:
> 
> My code is similar to:
> 
> :
> :
> cat("\n","Enter value:: ","\n")
> y<-scan(n=1)
> a <- b*y
> cat("\n","Enter new value::","\n")
> y<-scan(n=1)
> :
> :
> 
> Now if I run the whole script then something like this happens:
> 
> :
> :
> cat("\n","Enter value::","\n")
> 
>  Enter value::
>> y<-scan(n=1)
> 1: a <- b*y
> Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,
> :
>         scan() expected 'a real', got 'a'
>> cat("\n","Enter new value::","\n")
> 
>  Enter new value::
>> y<-scan(n=1)
> 1: 2
> Read 1 item
> :
> :
> 
> Is there any solution to this problem or shall I execute my script in two
> parts:
> First part:
> 
> :
> :
> cat("\n","Enter value:: ","\n")
> y<-scan(n=1)
> 
> and second part:
> 
> a <- b*y
> cat("\n","Enter new value::","\n")
> y<-scan(n=1)
> :
> :
> 
> Any help will be greatly appreciated.

-- 
Petr Klasterecky
Dept. of Probability and Statistics
Charles University in Prague
Czech Republic



More information about the R-help mailing list