Hello, I have noticed a behavior that I don't understand. When I call the following function from the prompt. test <- function(){ a <- readline("selection: ") a }> test() > selection: |I can only type one character and the readline function exits before I can press enter. however test1 <- function(){ a <- readline("selection:") a }> test1() > selection:|works as expected.> selection: abc[Ret]However calling directly readline with a space in the prompt does what I would expect.> a <- readline("selection: ") > selection: abc[Ret] > a > "abc"It is the expected behavior or am I missing something? Best regards, Jeremie -- Jeremie Juste> R version 4.0.3 (2020-10-10)
Hi Jeremie, Try this: test <- function() { a<-readline("selection: ") return(a) } If it starts working, it could be a difference in the way Windows R handles text input. Both work okay for me on fedora linux. Jim On Tue, Feb 9, 2021 at 12:29 AM Jeremie Juste <jeremiejuste at gmail.com> wrote:> > Hello, > > I have noticed a behavior that I don't understand. When I call the > following function from the prompt. > test <- function(){ > a <- readline("selection: ") > a > } > > > test() > > selection: | > I can only type one character and the readline function exits before I can > press enter. > > however > > test1 <- function(){ > a <- readline("selection:") > a > } > > test1() > > selection:| > works as expected. > > selection: abc[Ret] > > However calling directly readline with a space in the prompt does what I > would expect. > > > a <- readline("selection: ") > > selection: abc[Ret] > > a > > "abc" > > It is the expected behavior or am I missing something? > > Best regards, > Jeremie > -- > Jeremie Juste > > R version 4.0.3 (2020-10-10) > > ______________________________________________ > R-help at 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.
On Mon, 08 Feb 2021 14:28:33 +0100 Jeremie Juste <jeremiejuste at gmail.com> wrote:> Hello, > > I have noticed a behavior that I don't understand. When I call the > following function from the prompt. > test <- function(){ > a <- readline("selection: ") > a > } > > > test() > > selection: | > I can only type one character and the readline function exits before > I can press enter. > > however > > test1 <- function(){ > a <- readline("selection:") > a > } > > test1() > > selection:| > works as expected. > > selection: abc[Ret] > > However calling directly readline with a space in the prompt does > what I would expect. > > > a <- readline("selection: ") > > selection: abc[Ret] > > a > > "abc" > > It is the expected behavior or am I missing something?Works fine for me, with or without the space in the prompt string. There *must* be something flaky in your system, but I'm damned if I can come up with any useful suggestions for tracking down just where that flakiness lies. Sorry. Perhaps try re-installing R??? cheers, Rolf Turner -- Honorary Research Fellow Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276
>>>>> Jeremie Juste >>>>> on Mon, 08 Feb 2021 14:28:33 +0100 writes:> Hello, > I have noticed a behavior that I don't understand. When I call the > following function from the prompt. > test <- function(){ > a <- readline("selection: ") > a > } >> test() >> selection: | > I can only type one character and the readline function exits before I can > press enter. > however > test1 <- function(){ > a <- readline("selection:") > a > } >> test1() >> selection:| > works as expected. >> selection: abc[Ret] > However calling directly readline with a space in the prompt does what I > would expect. >> a <- readline("selection: ") >> selection: abc[Ret] >> a >> "abc" > It is the expected behavior or am I missing something? > Best regards, > Jeremie > -- > Jeremie Juste >> R version 4.0.3 (2020-10-10) Given that the above works fine in Linux (for Jim Lemon and Rolf Turner), could you tell us *how* you use R? In the (Windows) RGui or from Rstudio or ESS or yet another way? Usually the UI (user interface) should not matter, but rather the R version etc. But the UI may be important for a function like readline() which does UI .. Martin