Passing Variable to "R"

For questions regarding programming in the EViews programming language.

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

kcaron
Posts: 89
Joined: Wed Mar 04, 2015 11:46 am

Passing Variable to "R"

Postby kcaron » Mon Mar 25, 2024 10:54 am

I'm trying to use EViews with R.

My program begins in EViews and asks the user for some information:

- series to forecast in R, called %fcst_series
- start year for forecast, called !start_year
- start month for forecast, called !start_month
- frequency of data, called !frequency

My code then tries to feed these variables into the R code starting with:

xon
fcst_series <- ts({%fcst_series}, start = c({!start_year},{!start_month}), frequency = {!frequency})

However, R doesn't like {%fcst_series} formatting. It appears to reject the "{}" and the "%"...

I can't figure out what the right way is to transfer this information to R.

Any ideas would be greatly appreciated!

Many thanks,

KC

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

Re: Passing Variable to "R"

Postby EViews Gareth » Mon Mar 25, 2024 10:57 am

Presumably you've already used XPUT to transfer the data across, and the issue is referencing that variable in R?
Follow us on Twitter @IHSEViews

kcaron
Posts: 89
Joined: Wed Mar 04, 2015 11:46 am

Re: Passing Variable to "R"

Postby kcaron » Mon Mar 25, 2024 10:58 am

Correct...

I had no issue moving the data to R... Just how to get the variables across into R.

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

Re: Passing Variable to "R"

Postby EViews Gareth » Mon Mar 25, 2024 11:19 am

If you have something like:

Code: Select all

%fcast_series = "X"
xput {%fcast_series}

xon
fcst_series<-ts({%fcst_series})
xoff


that will be passed into R as:

Code: Select all

fcast_series<-ts("x")

which will cause the error because R is not expecting the quotes. So you'd need to use R to remove the quotes.

Perhaps an easier way is to do this:

Code: Select all

%fcast_series = "X"
xput(name=foo) {%fcast_series}

xon
fcst_series<-ts(foo)
xoff
Follow us on Twitter @IHSEViews

kcaron
Posts: 89
Joined: Wed Mar 04, 2015 11:46 am

Re: Passing Variable to "R"

Postby kcaron » Mon Mar 25, 2024 11:32 am

I appreciate that. But what about passing a parameter like "frequency", for example?

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

Re: Passing Variable to "R"

Postby EViews Gareth » Mon Mar 25, 2024 1:52 pm

Don't put it in braces.
Follow us on Twitter @IHSEViews


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 17 guests