Bug 16350 - Rscript: block ignored on missing closing brace without warning
Summary: Rscript: block ignored on missing closing brace without warning
Status: CLOSED FIXED
Alias: None
Product: R
Classification: Unclassified
Component: Language (show other bugs)
Version: R 3.1.3
Hardware: ix86 (32-bit) Linux-Ubuntu
: P5 normal
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2015-04-29 09:37 UTC by K Antal
Modified: 2015-05-01 19:16 UTC (History)
3 users (show)

See Also:


Attachments
for loop with forgotten brace at end (318 bytes, application/x-download-me-with-something)
2015-04-29 09:37 UTC, K Antal
Details

Note You need to log in before you can comment on or make changes to this bug.
Description K Antal 2015-04-29 09:37:33 UTC
Created attachment 1809 [details]
for loop with forgotten brace at end

Rscript ignores unfinished block of commands with no warning.

----
#!/usr/bin/Rscript

cat("Hello ");

{
    cat("World\n");
#} missing brace: code is not executed, no warning emitted, exit code is 0

----
Comment 1 K Antal 2015-04-29 09:46:55 UTC
Similar behaviour for unfininished parenthesis

---
#!/usr/bin/Rscript

cat("Hello ");

(
    cat("World\n")
# ) # missing paren: code is not executed, no warning emitted, exit code is 0
---
Comment 2 Peter Dalgaard 2015-04-29 14:17:37 UTC
Command-line R doesn't protest at unterminated commands either. E.g.,

pd$ echo "1+" | R -q --vanilla
> 1+
+ 
pd$

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.
Comment 3 K Antal 2015-04-29 16:16:29 UTC
> 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
17:     do.something(j,k,l);
18: }}
   ^
> 
---
> 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
8: 
  ^
> 
---
> source('./one-plus.r' )
Error in source("./one-plus.r") : 
  ./one-plus.r:2:0: unexpected end of input
1: 1+
   ^
---

Note: source() emits error when called from plain R as well as when
called from a script executed by Rscript.
Comment 4 Duncan Murdoch 2015-05-01 17:38:44 UTC
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...
Comment 5 Peter Dalgaard 2015-05-01 18:06:29 UTC
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.
Comment 6 Duncan Murdoch 2015-05-01 19:16:04 UTC
I have fixed this now; just running tests before I commit.