From r@lf@@tubner @ending from d@q@n@@com  Mon May 28 12:13:57 2018
From: r@lf@@tubner @ending from d@q@n@@com (Ralf Stubner)
Date: Mon, 28 May 2018 12:13:57 +0200
Subject: [Rd] readLines function with R >= 3.5.0
In-Reply-To: <CABtg=KkuVHoX1tZ=+Lr7mDFrXvn5zdf3+Wmqhnv58GXZJS2KwQ@mail.gmail.com>
References: <32da856c-a60a-974f-65ab-d7123e12e813@daqana.com>
 <23307.48529.773039.904392@stat.math.ethz.ch>
 <23307.49323.908367.788461@stat.math.ethz.ch>
 <CABtg=KkuVHoX1tZ=+Lr7mDFrXvn5zdf3+Wmqhnv58GXZJS2KwQ@mail.gmail.com>
Message-ID: <f3388993-5e20-d7e5-346a-785d33fab27b@daqana.com>

On 28.05.2018 11:07, G?bor Cs?rdi wrote:
> stdin() is not the same as file("stdin"), see the note in ?stdin.

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)
>

>>>>>>> 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.

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 at daqana.com

Sitz: Potsdam
Register: AG Potsdam HRB 27966 P
Ust.-IdNr.: DE300072622
Gesch?ftsf?hrer: Prof. Dr. Dr. Karl-Kuno Kunze


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20180528/945902d8/attachment.sig>


[Rd] readLines function with R >= 3.5.0
Ralf Stubner