Saving data in R

For requesting general information about EViews, sharing your own tips and tricks, and information on EViews training or guides.

Moderators: EViews Gareth, EViews Moderator

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

Saving data in R

Postby startz » Thu Mar 31, 2022 12:35 pm

If you save a workfile in R you get a nice dataframe with one object for each series. The series are appropriately dated. Can someone tell me how I retrieve those dates in R? The documentation doesn't seem to say.

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

Re: Saving data in R

Postby EViews Steve » Fri Apr 01, 2022 8:14 am

R data.frames have a row.names attribute that we use when we create them for a series. These names are just strings so we place our dates into those in string format.

To retrieve them, use the following command:

Code: Select all

attr(x, 'row.names')

(where 'x' is a data.frame)

Example:
2022-04-01_08h09_08.png
2022-04-01_08h09_08.png (7.8 KiB) Viewed 2724 times

If you want the dates in actual date format, you'll have to push the @date value to R as well as your series, like this:

Code: Select all

xput(name=xx) x @date

which results in this:
2022-04-01_08h12_50.png
2022-04-01_08h12_50.png (5.15 KiB) Viewed 2724 times

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

Re: Saving data in R

Postby startz » Fri Apr 01, 2022 8:20 am

That's very helpful. It's a little weird though that if you SaveAs and choose Excel you get a dialog to choose series but you don't get that dialog if you choose R.

Maybe some part of your response Steve could make its way into the documentation, which is a bit sparse on what gets passed to R under what circumstances.

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

Re: Saving data in R

Postby EViews Steve » Fri Apr 01, 2022 12:53 pm

The SaveAs difference was caused because the normal Write specification dialog didn't support vectors/matrices. When you save a workfile as an RData file, it actually pushes all series & vectors/matrices to the file. We should've updated the Write specification dialog to support the other object types, but we didn't do that and haven't done so yet.

Our RData save facility also depends on having the External R connection setup as it uses that to perform the entire operation. So if you wanted to save a single series (or a set of series matching a name pattern), you could just do the following and it would be exactly the same as what WFSAVE would do.

Code: Select all

XOPEN(r)
XPUT gdp*
XRUN save.image("c:/files/out.rdata")
XCLOSE

I could submit my recent comment about R data.frames to our documentation, but my guess is that most R data.frame users were already familiar with what row names are in a data.frame. Obviously we don't want to write documentation for other software, but I get your point. We should probably update all of our docs on all of our external interfaces (R, MATLAB, & Python).

Oh, and I discovered an easier way of getting the row.names attribute in R:

Code: Select all

rownames(xx)

returns a character array of all the row names in data.frame xx.

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

Re: Saving data in R

Postby startz » Fri Apr 01, 2022 1:15 pm

But it would be good if the documentation said that dates are pushed out a row names.

And while I am whining about documentation...

(1) if you type R into the online search you get told (no results)
(2) when you get yourself to http://www.eviews.com/help/helpintro.html#page/content%2Fexternal-EViews_COM_Automation_Client_Support_(MATLAB%2C_R%2C.html%23ww1671199 you'll see that EViews 11 is referenced. Not wrong, but doesn't look good.

fmramos
Posts: 96
Joined: Fri Sep 19, 2008 7:30 am
Location: Sao Paulo / Brazil
Contact:

Importing a R dataframe to EViews

Postby fmramos » Mon Oct 03, 2022 5:30 pm

Hi guys!

I wonder if someone has an idea about how to import a data.frame or a ts object from R to EViews BUT let the own data frame contain data to inform EViews about the sample?

I'd use xget(type=series, name=series) seriesY, but I don't want a sequential read, but a match read.

like...

df$date & df$value to a series object inside EViews?

date value
12/aug 100
13/aug null
14/aug 102
... ...

Any suggestion is more than welcome!

Best, Fabio

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13060
Joined: Tue Sep 16, 2008 5:38 pm

Re: Saving data in R

Postby EViews Gareth » Tue Oct 04, 2022 8:52 am

I think import into a new page, then copy from that source page to your destination page.
Follow us on Twitter @IHSEViews

fmramos
Posts: 96
Joined: Fri Sep 19, 2008 7:30 am
Location: Sao Paulo / Brazil
Contact:

Re: Saving data in R

Postby fmramos » Tue Oct 04, 2022 9:48 am

Yeap. This is possible. There are also a EViewsR package. But it is not optimal. I'm using R to push data in JSON format through Central Bank and other local statistical bureaus. I'd like to send all data originally in daily or monthly basis to EViews databases directly or through a program. Most likely I'll have to first to export to XLS and after import to EViews database or using EViewsR package to store them from R to DB file... Will make some trials here...

Tks! F

EViews Gareth wrote:I think import into a new page, then copy from that source page to your destination page.

sagirumati
Posts: 8
Joined: Mon May 16, 2022 2:47 am

Re: Saving data in R

Postby sagirumati » Sat Oct 29, 2022 5:49 am

startz wrote:If you save a workfile in R you get a nice dataframe with one object for each series. The series are appropriately dated. Can someone tell me how I retrieve those dates in R? The documentation doesn't seem to say.




I think my R package, EviewsR, can help.

To import all pages of a workfile into R as a dataframe:


Code: Select all

library(EviewsR)
import_series(wf="myWorkfile")



To import all series objects from specific page(s), for example myPage, of a workfile into R as a dataframe:

Code: Select all

library(EviewsR)
import_series(wf="myWorkfile",page="myPage")


To import specific page(s), for example myPage, and specific series object(s), for example y, from a workfile into R as a dataframe:

Code: Select all

library(EviewsR)
import_series(wf="myWorkfile",page="myPage",series="y")



If you want the imported series objects to be an xts object, use class="xts" in the impor_series function argument

To access the imported dataframe or xts object, related to myPage, in base R:

Code: Select all

eviews$mypage


Note that `myPage` changes to `mypage` because EviewsR is designed to convert all imported EViews objects to lower case in R.

Note that `eviews` is an environment created by EviewsR package to save all imported EViews objects in base R. In R Markdown or Quarto, the package uses the chunk label as the new environment, instead of `eviews`.


Return to “General Information and Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 5 guests