Bug 15941 - Long, multiple-expression console input causes premature EOF
Summary: Long, multiple-expression console input causes premature EOF
Status: REOPENED
Alias: None
Product: R
Classification: Unclassified
Component: I/O (show other bugs)
Version: R 3.1.1
Hardware: All All
: P5 normal
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2014-08-20 01:13 UTC by Ken Yamaguchi
Modified: 2014-08-21 17:34 UTC (History)
3 users (show)

See Also:


Attachments
long vector assignment followed by a print (32.00 KB, text/plain)
2014-08-20 01:13 UTC, Ken Yamaguchi
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ken Yamaguchi 2014-08-20 01:13:46 UTC
Created attachment 1648 [details]
long vector assignment followed by a print

The attached long (~32Kb) single-line file, consisting of a single vector assignment followed by a print, should print "ok" via Rscript. "Rscript test.R" exits before the print.

The error occurs based on input length not content. Adding a single character to the variable name or to a number causes correct execution, as does splitting the statements to two lines.

The problem appears limited to the console input. 'script("test.R")' executes correctly.

The problem occurs with R 3.1.1 on OS X, R 2.15.0 on OS X, and R 2.15.1 on Linux.

Thank you!
Comment 1 Martin Maechler 2014-08-20 11:20:51 UTC
Hmm, the  parse  help page contains

     ...... The line-length limit is 4095 bytes when reading from the console
     (which may impose a lower limit: see ‘An Introduction to R’).

and you say   "The problem appears limited to the console input"
so there would not be a bug at all.

On the other hand,   "Rscript test.R'  is not about console input.

I've also tried  R CMD BATCH  test.R   as an alternative, and that also
gives a problem. It produces a test.Rout; but the   print("ok")  part is not
executed.

NB: The line line length of the example file (test.R) is very close to 
    2^15 = 32768
Comment 2 Ken Yamaguchi 2014-08-20 18:15:51 UTC
I'd poked around with a debugger and saw the parse occurring with function R_ReplConsole in the call stack (R 2.15.1 on Linux using argument -f test.R), so I must be using console in an internal sense. :)

The parse appears to be using a 4096-length buffer, running out of space, adding one more buffer, then starting the parse over until the buffer chain is long enough. Not particularly efficient but should eventually work for arbitrarily long input. That said, shortening the vector assignment by 4096 characters avoids the bug. Lengthening the print statement also avoids the bug. The problem appears dependent on (1) the character length of the vector assignment and (2) the presence of the second expression.