Created attachment 1809 [details]
for loop with forgotten brace at end
Rscript ignores unfinished block of commands with no warning.
#} missing brace: code is not executed, no warning emitted, exit code is 0
Similar behaviour for unfininished parenthesis
# ) # missing paren: code is not executed, no warning emitted, exit code is 0
Command-line R doesn't protest at unterminated commands either. E.g.,
pd$ echo "1+" | R -q --vanilla
And the same thing happens if you hit ctr-d at the "+" prompt in an iteractive sesseion.
It's not really a bug that Rscript behaves similarly to plain R, but perhaps we should always warn if we reach EOF within a partially parsed expression.
> It's not really a bug that Rscript behaves similarly to plain R
Plain R does show a '+' prompt, Rscript gives no clue.
Also source() does emit an error on unfinished expressions:
> source('./Rscript-missing-brace.r' )
Error in source("./Rscript-missing-brace.r") :
./Rscript-missing-brace.r:19:0: unexpected end of input
> source('./Rscript-missing-paren.r' )
Error in source("./Rscript-missing-paren.r") :
./Rscript-missing-paren.r:9:0: unexpected end of input
7: # ) # missing paren
> source('./one-plus.r' )
Error in source("./one-plus.r") :
./one-plus.r:2:0: unexpected end of input
Note: source() emits error when called from plain R as well as when
called from a script executed by Rscript.
I agree that we should get the same behaviour as source() gives, i.e. an error if a statement is incomplete at the EOF. I'll take a look...
Yup. source() is a somewhat different beast because it parses the entire file before evaluating anything, but it does sound like a no-brainer to detect EOF during an incomplete parse. That goes both for Rscript and other uses of the R interpreter, interactive or not.
I have fixed this now; just running tests before I commit.