[R] R programming question

From: Nelson, Gary (FWE) <Gary.Nelson_at_state.ma.us>
Date: Thu, 14 Jun 2007 11:02:13 -0400


Dear All.,

I've created R-code for which a user will be asked to choose between 2 analyses. I've written one function for each type of analysis. Within each function, the users is prompted to enter information. An example is:  

cat("Enter value for lower Linf :\n")

     L1<-scan(n=1)
     cat("Enter value for upper Linf :\n")
     L2<-scan(n=1)
     cat("Enter Linf interval :\n")
     int_L<-scan(n=1)
     cat("Enter value for lower K :\n")
     K1<-scan(n=1)
     cat("Enter value for upper K :\n")
     K2<-scan(n=1)
     cat("Enter K interval :\n")
     int_K<-scan(n=1)

I thought I could evaluate and run the appropriate function at the end of the program by:

if(event==1) explore() else evaluate()

If I run the whole program and either explore() or evaluate() is run, the first four prompted entries are skipped over. The console output for event==1 is TRUE looks like:

> if(event==1) explore() else evaluate()
Enter value for lower Linf :
1:
Read 0 items
Enter value for upper Linf :
1:
Read 0 items
Enter Linf interval :
1:
Read 0 items
Enter value for lower K :
1:
Read 0 items
Enter value for upper K :
1:

I then tried another way. I created

runcase<-ifelse(event==1,"explore","evaluate")

At the bottom of the program I used:

eval(call(x=runcase))

But I still get the same problem.

Any suggestions?  

Thanks for your help

Gary A. Nelson, Ph.D
Massachusetts Division of Marine Fisheries 30 Emerson Avenue
Gloucester, MA 01930
Phone: (978) 282-0308 x114
Fax: (617) 727-3337
Email: Gary.Nelson_at_state.ma.us



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. Received on Thu 14 Jun 2007 - 15:34:16 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 14 Jun 2007 - 17:31:59 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.