Page 1 of 1

Saving data in R

Posted: Thu Mar 31, 2022 12:35 pm
by startz
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.

Re: Saving data in R

Posted: Fri Apr 01, 2022 8:14 am
by EViews Steve
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 68964 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 68964 times

Re: Saving data in R

Posted: Fri Apr 01, 2022 8:20 am
by startz
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.

Re: Saving data in R

Posted: Fri Apr 01, 2022 12:53 pm
by EViews Steve
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.

Re: Saving data in R

Posted: Fri Apr 01, 2022 1:15 pm
by startz
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.ht ... 3ww1671199 you'll see that EViews 11 is referenced. Not wrong, but doesn't look good.

Importing a R dataframe to EViews

Posted: Mon Oct 03, 2022 5:30 pm
by fmramos
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

Re: Saving data in R

Posted: Tue Oct 04, 2022 8:52 am
by EViews Gareth
I think import into a new page, then copy from that source page to your destination page.

Re: Saving data in R

Posted: Tue Oct 04, 2022 9:48 am
by fmramos
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
I think import into a new page, then copy from that source page to your destination page.

Re: Saving data in R

Posted: Sat Oct 29, 2022 5:49 am
by sagirumati
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`.