From l@wrence@mich@el @ending from gene@com  Thu Sep 13 14:14:46 2018
From: l@wrence@mich@el @ending from gene@com (Michael Lawrence)
Date: Thu, 13 Sep 2018 05:14:46 -0700
Subject: [Rd] Bug 17432 in readLines with R >= 3.5.0 still a problem
In-Reply-To: <MEXPR01MB1527ADCFA3441A6E943C9D96C91B0@MEXPR01MB1527.ausprd01.prod.outlook.com>
References: <MEXPR01MB1527ADCFA3441A6E943C9D96C91B0@MEXPR01MB1527.ausprd01.prod.outlook.com>
Message-ID: <CAOQ5Nycb=wCiwrFOZz1hQSi0eDA=T-N1B+Ep+1=w++X=8Wxj+w@mail.gmail.com>

Thanks, I responded to this on bugzilla.
On Wed, Sep 12, 2018 at 9:04 AM Chris Culnane
<christopher.culnane at unimelb.edu.au> wrote:
>
> Bug 17432 (https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=17432) is still a problem when using pipes for IPC.
>
> The bug is evident when calling R from another process and trying to communicate via StdIn. R will buffer the input and not read lines until the buffer is exceeded or StdIn is closed by the sending process. This prevents interactive communication between a calling process and a child R process.
>
> From a quick look at the source code, it looks like the bug is caused by only disabling buffering when isatty() returns true for a file descriptor (connections.c). This fixes the original bug when the script is run in a terminal, but doesn't help for pipes, which will return false for isatty().
>
> An example R script and python script are provided to demonstrate the problem:
>
> R script (example.r):
> ================
> f <- file("stdin")
> open(f)
> while(length(line <- readLines(f,n=1)) > 0) {
>   write(line, stderr())
> }
>
> Python3 script:
> ============
> import sys, os, subprocess
> process = subprocess.Popen(['Rscript', 'example.r'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
> for line in sys.stdin:
>     process.stdin.write((line + '\n').encode('utf-8'))
>     process.stdin.flush()
>
>
> Expected Behaviour:
> Run python script, each line entered is echoed back immediately by the R script - which is what happens on 3.4.4
>
> Observed Behaviiour on >=3.5.0 (include devel):
> The R script does not process lines as they are sent, it only receives them when StdIn is closed.
>
>
> Best Regards
>
> Chris
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



[Rd] Bug 17432 in readLines with R >= 3.5.0 still a problem
Michael Lawrence