title: What is the correct way to ask for user input in an R program?
body: <p>The my program below(which is in two parts) works  if I run them separately – that is, if I paste the first part into the R Console, run it and then paste the second  and run it. However, that is not how I want it. I want to run the whole program at once. If I do that it shows the following error in my console :</p>
  
  <pre><code>1: 
  Read 0 items
  1: 
  Read 0 items
  Error in while ((n &lt;= 0) | (acr &lt;= 0) | (acr &gt;= 1)) { : 
    argument is of length zero
  </code></pre>
  
  <p>I have tried to identify the problem but I have not been able find the root cause. I would be more than glad, if someone could come to my aid.</p>
  
  <pre><code>#**FIRST PART OF THE PROGRAM**
  
  n &lt;- -2
  acr &lt;- -2
  while((n&lt;=0) | (acr&lt;=0) | (acr&gt;=1)) {
     print("enter a  positive integer and the average cancellation rate between 0 and 1  
                  you want")
     try(n &lt;- scan(what=integer(), nmax=1), silent=TRUE)
     try(acr &lt;- scan(what=double(), nmax=1), silent=TRUE)
  }
  
  
  #**SECOND PART OF THE PROGRAM**
  
  bygrace &lt;- read.table("C:\\MyRfolder\\bygrace.txt", header=FALSE)
  r &lt;- nrow(bygrace)
  c &lt;- ncol(bygrace)
  copybygrace &lt;- array(bygrace, dim=c(r, c))
  copybygrace &lt;- bygrace[-((n+1):r), ]
  write.table(copybygrace,file="C:\\MyRfolder\\copybygrace.txt", sep="\t")
  copybygrace &lt;- read.table("C:\\MyRfolder\\copybygrace.txt", header=TRUE)
  </code></pre>