xget and dataframes

For questions regarding programming in the EViews programming language.

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

Elderfield.A
Posts: 78
Joined: Thu Jul 11, 2019 10:47 pm

xget and dataframes

Postby Elderfield.A » Thu Jul 13, 2023 10:18 pm

Hi,

Is there any way to pass a dataframe object from R to EViews using XGET. The below works fine

Code: Select all

xget(name=df, type=matrix) "as.matrix(df)"


However, the matrix object does not have any column names (there are 138 columns). Is there any way to pass the names to EViews either with the object (so the column names are preserved) or as a string vector?

Thanks

Adam

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

Re: xget and dataframes

Postby EViews Steve » Fri Jul 14, 2023 8:03 am

EViews supports R data.frames, but perhaps your data.frame is in a format that EViews doesn't recognize?

To get a better understanding of how EViews supports data.frames, try the following simple example:

Code: Select all

wfcreate a 1991 2000
series x = @trend
series y = @nrnd
xopen(r)
xput(rtype=df, name=both) x y
delete x
delete y
xget both
You should end up with the same X & Y series back from R.

Take a close look at the "both" data.frame in R and inspect it's attributes. You'll see that it has "$row.names", "$names", and "$is.series" attributes that help EViews understand what each column is.
2023-07-14_07h55_56.png
2023-07-14_07h55_56.png (5.08 KiB) Viewed 9336 times

Also, when you run the final XGET command above, you'll see that EViews is retrieving each column from the data.frame separately:
2023-07-14_07h54_39.png
2023-07-14_07h54_39.png (3.1 KiB) Viewed 9336 times

So if you're having trouble getting your own data.frame in a single call, try retrieving each column one at a time by using the "data.frame$column" nomenclature, like this:

Code: Select all

xget(name=xx, type=series) both$x

Steve

Elderfield.A
Posts: 78
Joined: Thu Jul 11, 2019 10:47 pm

Re: xget and dataframes

Postby Elderfield.A » Mon Jul 17, 2023 12:00 am

Thanks Steve - very detailed and useful answer I appreciate it!

Yep, loading the DF works just fine. Is there a vignette or something that details the x family functions that I can read? The whitepaper seems a little limited.

As a side note, is COM automation on the cards? I'm currently achieving what I need via using R to write an EViews program, which I can run via the shell. It would be awesome to have COM automation ability available like you do with Excel VBA.

Thanks

Adam

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

Re: xget and dataframes

Postby EViews Steve » Mon Jul 17, 2023 7:10 am

We provide an online reference for our various commands (including all the X commands), here's the page for XGET. There's also a page that discusses using EViews with R.

EViews has had the ability to be a COM Automation server (like Excel) since EViews 7.

And since we already have our own programming language, you can just use that to program EViews. Here's the whitepaper that discusses how to use the EViews COM Automation interface. It has examples of controlling EViews from VBA and Visual Studio projects.

Steve

Elderfield.A
Posts: 78
Joined: Thu Jul 11, 2019 10:47 pm

Re: xget and dataframes

Postby Elderfield.A » Mon Jul 17, 2023 1:16 pm

Great - that is really handy!

Thanks for sharing the link to the COM whitepaper. I have to admit, translating this to an R environment (as opposed to VBA) is a little beyond my capabilities. Do you have an example of how this could be achieved?

startz
Non-normality and collinearity are NOT problems!
Posts: 3775
Joined: Wed Sep 17, 2008 2:25 pm

Re: xget and dataframes

Postby startz » Mon Jul 17, 2023 2:57 pm

You might want to take a look at https://cran.r-project.org/web/packages/EviewsR/vignettes/EviewsR.html, which may give you a different, but easier, approach.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 7 guests