bpfaff / vars

Multivariate Time Series Models: VAR, SVAR and SVEC
40 stars 22 forks source link

Environment issue when nesting `irf(VAR())` inside function #17

Open nicolaiberk opened 1 year ago

nicolaiberk commented 1 year ago

Hi,

thanks for providing this great package!

I am trying to call irf(VAR) from inside a function with dynamic argument(s):

f1 <- function(max_lag = 6){

  vars::irf(vars::VAR(EuStockMarkets, lag.max = get("max_lag", env = parent.frame())))

}

f1(max_lag = 12)

This results in

Error in get("max_lag", env = parent.frame()) : 
  object 'max_lag' not found

I presume the issue has something to do with the definition of the environments in irf() or VAR(). I played around with the env argument but to little avail. Maybe this is helpful?