Saving data in R
Moderators: EViews Gareth, EViews Moderator
-
- Non-normality and collinearity are NOT problems!
- Posts: 3775
- Joined: Wed Sep 17, 2008 2:25 pm
Saving data in R
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 Developer
- Posts: 799
- Joined: Tue Sep 16, 2008 3:00 pm
- Location: Irvine, CA
Re: Saving data in R
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:
(where 'x' is a data.frame)
Example:
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:
which results in this:
To retrieve them, use the following command:
Code: Select all
attr(x, 'row.names')
(where 'x' is a data.frame)
Example:
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:
-
- Non-normality and collinearity are NOT problems!
- Posts: 3775
- Joined: Wed Sep 17, 2008 2:25 pm
Re: Saving data in R
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.
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 Developer
- Posts: 799
- Joined: Tue Sep 16, 2008 3:00 pm
- Location: Irvine, CA
Re: Saving data in R
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.
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:
returns a character array of all the row names in data.frame xx.
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.
-
- Non-normality and collinearity are NOT problems!
- Posts: 3775
- Joined: Wed Sep 17, 2008 2:25 pm
Re: Saving data in R
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.
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.
Importing a R dataframe to EViews
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
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
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13330
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Saving data in R
I think import into a new page, then copy from that source page to your destination page.
Follow us on Twitter @IHSEViews
Re: Saving data in R
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
Tks! F
EViews Gareth wrote:I think import into a new page, then copy from that source page to your destination page.
-
- Posts: 8
- Joined: Mon May 16, 2022 2:47 am
Re: Saving data in R
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 3 guests