1

Lets say I have the following script

k <- as.numeric(readline("Start Index: "))
tot <- NULL

for (i in 1:k){
    tot <- c(tot, i)
}
write.csv(tot, "test.csv")

I would like to run this script from the command line. How can I run it so that it still asks for the user input (k). Or otherwise can I add the value of k in the CMD command as argument? I am on Linux.

Dason
  • 60,663
  • 9
  • 131
  • 148
ECII
  • 10,297
  • 18
  • 80
  • 121
  • couple of these floating around [link](http://stackoverflow.com/questions/4547789/command-line-arguments-in-bash-to-rscript), [link](http://stackoverflow.com/questions/3433603/parsing-command-line-arguments-in-r-scripts), [link](http://stackoverflow.com/questions/4808169/r-command-line-passing-a-filename-to-script-in-arguments-windows), [link](http://stackoverflow.com/questions/1110363/is-there-a-package-to-process-command-line-options-in-r), [link](http://stackoverflow.com/questions/2151212/how-can-i-read-command-line-parameters-from-an-r-script) – GSee Jun 22 '12 at 21:59

1 Answers1

1

You might find the information in ?commandArgs helpful.

From the description:

 Provides access to a copy of the command line arguments supplied
 when this R session was invoked.
Dason
  • 60,663
  • 9
  • 131
  • 148
Matthew Plourde
  • 43,932
  • 7
  • 96
  • 113