[R] User input when running R code in batch mode

Bernd Kreuss prof7bit at googlemail.com
Tue Oct 27 16:43:19 CET 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Kaushik Krishnan wrote:
> Is there any way to make R stop for the user to enter values when
> running in batch mode either by changing the way I invoke scan() or
> readLines() or by using any other function?

At least on linux this works:

bernd at t40:~/r-test $ cat test.R

readline2 = function(prompt=""){
        cat(prompt)
        readLines("stdin", 1)
}

print(readline2("enter a number: "))

bernd at t40:~/r-test $ Rscript test.R
enter a number: 42
[1] "42"


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iD8DBQFK5xUSxT6R4jlFoh0RAkhTAKCB4qUjPlULL9vjUaLLxarTor2z1QCeNGHA
4B2VmkqtyEKMKKGUnt8sjiY=
=VYJs
-----END PGP SIGNATURE-----




More information about the R-help mailing list