[R-pkg-devel] Question "no visible binding for '<<-' assignment"

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Thu Apr 15 00:07:43 CEST 2021


On 14/04/2021 12:11 p.m., Federico Zanghi wrote:
> Hi :)
> 
> I'm here because i have a problem with my package...i have the function
> "SARMAX.refinement", clearly the problem is that i can't assign a variable
> on global environment from a function.
> So when i CHECK the package it gives me 1 Note that doesn't make me publish
> the package :(
> 
> The Note is this:
> 
> * checking R code for possible problems ... [20s] NOTE
> SARMAX.refinement: no visible binding for '<<-' assignment to 'xreg'
> 
> 
> The fact is that the function
> "model <- Arima(fit$data, order = arima_order,seasonal =
> list(order=seasonal_order,period=period), xreg = xreg)"
> 
> works only if i define xreg on the glob.env...

Then something is broken.  You need to change things: packages shouldn't 
be writing directly to the global environment.

I don't know the Arima function, but it's where I'd start looking.
> 
> I tried  using fitted(fit) instead of xreg but i cannot use predict because
> the function doesn't find "fitted(fit)" or xreg (even if i define xreg only
> inside the function with xreg <- fitted(fit)).
> 
> Anyone has any suggestions?
> (without completely change the function or the class...i'd like to
> maintain the current class to use all its functions)

Scoping for modelling functions is quite tricky.  The standard rules are 
that model variables are looked for in the data argument first, then the 
environment of the model formula.  "Model variables" include those 
referenced in the model formula, but also some others.


> P.S.
> 
> In order to being as clear as possible i paste the code i need to use:
> 
> arimaGGM <- SARMAX.refinement(GGM,arima_order = c(2,0,1),seasonal_order =
> c(1,0,0), period=4,display = F)
> predict(arimaGGM,newxreg = 1:100)
> 
> the data is also attached to the mail :)

No, it wasn't.  If you want more specific help, you should include a 
self-contained example in the text of your message.

Duncan Murdoch



More information about the R-package-devel mailing list