From randy.cs.lai at gmail.com  Wed Apr 25 23:34:38 2018
From: randy.cs.lai at gmail.com (Randy Lai)
Date: Wed, 25 Apr 2018 17:34:38 -0400
Subject: [Rd] readLines() for non-blocking pipeline behaves differently in R
 3.5
Message-ID: <4357736e-8888-45e2-96e0-a2e5985d87da@Spark>

It seems that the behavior of readLines() in R 3.5 has changed for non-blocking pipeline.


Consider the following R script, which reads from STDIN line by line.
```
con <- file("stdin")
open(con, blocking = FALSE)

while (TRUE) {
? ? txt <- readLines(con, 1)
? ? if (length(txt) > 0) {
? ? ? ? cat(txt, "\n", file = stdout())
? ? }
? ? Sys.sleep(0.1)
}
close(con)

```

In R 3.4.4, it works as expected.

```
(randymbpro)-Desktop$ echo "abc\nfoo" | R --slave -f test.R
abc
foo
```

In R 3.5, only the first line is printed
```
(randymbpro)-Desktop$ echo "abc\nfoo" | R --slave -f test.R
abc
```

Is this change expected? ?If I change `blocking` to `TRUE` above, the above code would
work. But I need non-blocking connection in my use case of piping buffer from
another program.

Best,

R 3.5 @ macOS 10.13


Randy


	[[alternative HTML version deleted]]



[Rd] readLines() for non-blocking pipeline behaves differently in R 3.5
Randy Lai