Page 1 of 1

Using R - unexpected end of input in

Posted: Mon Jan 11, 2021 8:40 am
by patrice
Hello,

I have an error using this R code from Eviews 11. If I put all the if code under one line, there is no issue (the code below also works in R Studio of course). There is also this kind of error using for loop in multiple lines.

Code: Select all

xopen(type=r)

xon

a<-10
if (a==10) {
  cat('\nYes')
} else {
  cat('\nNo')
}
xoff
xclose


The error message:
R returned an error
Error: unexpected end of input in "if (a==10) {" in "IF (A==10) {"
on line 6.

As I said, this works:

Code: Select all

xopen(type=r)

xon

a<-10
if (a==10) {  cat('\nYes')} else {  cat('\nNo')}
xoff
xclose

Re: Using R - unexpected end of input in

Posted: Mon Jan 11, 2021 2:50 pm
by EViews Steve
Using R within EViews is not entirely the same as using R directly. One of the main differences is that whenever you hit Return/Enter in EViews, the line that you just wrote is sent to R as it is. When you do this in R directly, it can expect a continuation of the command on the following lines, but the DLL that we call from within EViews doesn't have that ability. EViews always has to send the full if statement as a single line or R will report it as an error.

Even within an XON/XOFF block, EViews can only send the lines one at a time as we don't have the ability to parse a multi-line R command and send them all together for you.

So the behavior you are seeing is as expected and is not an error, just a limitation.

Steve

Re: Using R - unexpected end of input in

Posted: Wed Jan 13, 2021 8:36 am
by patrice
Thanks a lot for your quick reply