2

I want this code to ask for the value of x while I run the whole script but it doesn't wait for the input. Although it waits for a file to get uploaded by the user at line 3. While running it line by line this works fine and that is obvious. What is the best method to this?

x = readline("how many columns?")
Data = read.csv(file.choose())
columns = matrix(rep(0, dim(Data[1] * x), nrow = dim(Data)[1]))
Data = cbind(Data, columns)
Uwe
  • 41,420
  • 11
  • 90
  • 134
Yogesh
  • 1,384
  • 1
  • 12
  • 16

1 Answers1

3

because when you run whole the script, it can't wait to get the x value. You can put the script into a function, then call the function. It will run line by line.

your_func_name <- function()
{
     #your script
}

Whenever you wanna call the script:

#just call the function
your_func_name()
Chau Pham
  • 4,705
  • 1
  • 35
  • 30