[Rd] readLines function with R >= 3.5.0
Martin Maechler
m@echler @ending from @t@t@m@th@ethz@ch
Mon May 28 16:38:35 CEST 2018
>>>>> Ralf Stubner
>>>>> on Mon, 28 May 2018 12:13:57 +0200 writes:
> On 28.05.2018 11:07, Gábor Csárdi wrote:
>> stdin() is not the same as file("stdin"), see the note in ?stdin.
Of course it is not the same, otherwise using one for the other
had no effect, but you are right:
it is *NOT* a solution to the problem
> In particular stdin() works in an interactive session but not when R -f
> / Rscript is used, since it does not wait for the user to input anything:
> $ R -f readLines.R
> R version 3.5.0 (2018-04-23) -- "Joy in Playing"
> Copyright (C) 2018 The R Foundation for Statistical Computing
> Platform: x86_64-pc-linux-gnu (64-bit)
> [...]
>> create_matrix <- function() {
> + cat("Write the numbers of vertices: ")
> + user_input <- readLines(stdin(), n=1)
> + user_input <- as.numeric(user_input)
> + print(user_input)
> + }
>> create_matrix()
> Write the numbers of vertices: numeric(0)
>>
oh dear... yes, that is true ..
>>>>>>>> Martin Maechler
>>>>>>>> on Mon, 28 May 2018 10:28:01 +0200 writes:
>>> > It "works" if you additionally (the [Enter], i.e., EOL) you also
>>> > "send" an EOF -- in Unix alikes via <Ctrl>-D
> From my point of view this is a reasonable workaround for now.
I'm glad to hear that.
Then, I now do think this needs to be dealt with as a bug
(but I'm not delving into fixing it!)
Martin
> Thanks
> Ralf
> --
> Ralf Stubner
> Senior Software Engineer / Trainer
> daqana GmbH
> Dortustraße 48
> 14467 Potsdam
> T: +49 331 23 61 93 11
> F: +49 331 23 61 93 90
> M: +49 162 20 91 196
> Mail: ralf.stubner using daqana.com
> Sitz: Potsdam
> Register: AG Potsdam HRB 27966 P
> Ust.-IdNr.: DE300072622
> Geschäftsführer: Prof. Dr. Dr. Karl-Kuno Kunze
> x[DELETED ATTACHMENT signature.asc, application/pgp-signature]
> ______________________________________________
> R-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
More information about the R-devel
mailing list