interactive session

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

interactive session

fkiraz11
Hi guys,

I examined lots of manuals' examples  but I could not exactly manage what I
wanted. I want to insert a function in my test code and make it an interactive
and semi-automatic process. I want the user to enter a valid number before being
able to continue and then I want the code to use that number as an input to the
next command. If the thing user supplied is not a valid number, I want the code
ask again and again until the proper response comes. How can I do this. That
part of my code looks like this:

rm(list=ls())
library(gtools)
library(YaleToolkit)
library(xts)
 
### start of my wrong function!
f<-function(w){
 w<-readline("which data? ")
 w<-as.numeric(w)
 ifelse(is.numeric(w)=="TRUE", w, f())
 }
f()
##### end of my wrong function

v<- ## and output of my function should be a "v" for example which I can use it
in the next line (v<-w  or something like that??)
 
##the rest works fine
p<-paste("t", v, ".txt", sep = "")
t<-read.table(p, header=FALSE, sep="\t", dec=",",
blank.lines.skip=FALSE)
rownames(t)<-as.Date(t[,1],"%d.%m.%Y")
colnames(t)<-c("date","start","high","low","end","w.average","lot",
"volume")
x<-as.xts(t)
whatis(x)   
.
.

Could you help me with this problem?

Best,
Fatih



     
        [[alternative HTML version deleted]]


_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
Reply | Threaded
Open this post in threaded view
|

Re: interactive session

Arun.stat
Dear Fatih, if your problem is to let user to provide inputs of a function interactively then perhaps "http://r.789695.n4.nabble.com/Supplying-function-inputs-interactively-td2536003.html#a2536003" may be with some help.

PS: please never use the syntax "rm(list=ls())" when you give any example. User suddenly might find all his works gone if he tries to replicate your code in his current work session without noticing each and every details.

Thanks,