[R] Pause script at input from terminal (interactive use)

PIKAL Petr petr@p|k@| @end|ng |rom prechez@@cz
Tue Apr 23 09:22:16 CEST 2019


Hi

Maybe you could think about transfering **script** to **function**.

In function your construction seems to be OK.

Cheers
Petr

> -----Original Message-----
> From: R-help <r-help-bounces using r-project.org> On Behalf Of Luigi Marongiu
> Sent: Thursday, April 18, 2019 4:11 PM
> To: r-help <r-help using r-project.org>
> Subject: [R] Pause script at input from terminal (interactive use)
>
> Dear all,
> I am trying to write an interactive script where the user type some input from
> the terminal. I used readline() but when I launch the file with Rscript, the
> function is overwritten directly, there is no waiting for the user's input. For
> instance, this example:
>
> VAR1 = as.numeric(readline(prompt = "Enter something -> "))
> VAR2 = as.numeric(readline(prompt = "Enter something else -> "))
> if(is.na(VAR1)) VAR1 = 0
> if(is.na(VAR2)) VAR2 = "empty"
> cat("Input was: ", VAR1, " - ", VAR2, "\n")
>
> is executed till the end without typing anything on terminal :
>
> $ Rscript test.R
> Enter something ->
> Enter something else ->
> Input was:  0  -  empty
>
> I also tried with ',1' at the end of readline, but the effect is the same. I should
> use the interactive() function but I am confused on its use.
> It is possible to launch R scritps in the interactive mode in the first place? and if
> yes, how? Or would python or julia be better choices in this case?
> Thank you.
> --
> Best regards,
> Luigi
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
Osobní údaje: Informace o zpracování a ochraně osobních údajů obchodních partnerů PRECHEZA a.s. jsou zveřejněny na: https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about processing and protection of business partner’s personal data are available on website: https://www.precheza.cz/en/personal-data-protection-principles/
Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a podléhají tomuto právně závaznému prohláąení o vyloučení odpovědnosti: https://www.precheza.cz/01-dovetek/ | This email and any documents attached to it may be confidential and are subject to the legally binding disclaimer: https://www.precheza.cz/en/01-disclaimer/



More information about the R-help mailing list