Page 1 of 1

Passing Variable to "R"

Posted: Mon Mar 25, 2024 10:54 am
by kcaron
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

Re: Passing Variable to "R"

Posted: Mon Mar 25, 2024 10:57 am
by EViews Gareth
Presumably you've already used XPUT to transfer the data across, and the issue is referencing that variable in R?

Re: Passing Variable to "R"

Posted: Mon Mar 25, 2024 10:58 am
by kcaron
Correct...

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

Re: Passing Variable to "R"

Posted: Mon Mar 25, 2024 11:19 am
by EViews Gareth
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

Re: Passing Variable to "R"

Posted: Mon Mar 25, 2024 11:32 am
by kcaron
I appreciate that. But what about passing a parameter like "frequency", for example?

Re: Passing Variable to "R"

Posted: Mon Mar 25, 2024 1:52 pm
by EViews Gareth
Don't put it in braces.