Using R - unexpected end of input in

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt

patrice
Posts: 8
Joined: Tue Oct 12, 2010 2:10 am

Using R - unexpected end of input in

Postby patrice » Mon Jan 11, 2021 8:40 am

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

EViews Steve
EViews Developer
Posts: 795
Joined: Tue Sep 16, 2008 3:00 pm
Location: Irvine, CA

Re: Using R - unexpected end of input in

Postby EViews Steve » Mon Jan 11, 2021 2:50 pm

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

patrice
Posts: 8
Joined: Tue Oct 12, 2010 2:10 am

Re: Using R - unexpected end of input in

Postby patrice » Wed Jan 13, 2021 8:36 am

Thanks a lot for your quick reply


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 18 guests