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.stub...@daqana.com Sitz: Potsdam Register: AG Potsdam HRB 27966 P Ust.-IdNr.: DE300072622 Geschäftsführer: Prof. Dr. Dr. Karl-Kuno Kunze
signature.asc
Description: OpenPGP digital signature
______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel