[Rd] LM/GLM can't find weights vector from within a function (PR#13735)

From: <gaidys_at_uol.com.br>
Date: Mon, 01 Jun 2009 03:35:12 +0200 (CEST)

Full_Name: Alberto Gaidys
Version: 2.9.0
OS: Mac OS X 10.5.7
Submission from: (NULL) (

When calling LM or GLM from within a function, R gives a message error that it can't find the specified weights object "Erro em eval(expr, envir, enclos) : objeto 'W' não encontrado" (Error in eval(expr, envir, enclos) : object 'W' not found).

The call from within the user-defined function where the error happens is:


where rFormula is a text string, rData is a 1422 x 17 timeSeries data matrix, both passed from the console, i is a counter, W is a 1422 x 1 numeric vector of weights declared locally within the function.

The function definition is as follows:

   redls<-function(rFormula, rData, nStart, rBeta=1., nDelayed=3)

I already tried to define W externally to the function and parse it as a parameter, change its name, declare it as an array, declare it as a timeSeries object, with always the same error. Invoking glm instead of lm gives also the same error. The ls.str listing of W immediately before calling lm, showing it does exist, is:

   W : num [1:1422(1d)] 0.00628 0.0064 0.00654 0.00667 0.00681 ...

The exactly same lm call, with the objects created exactly the same way from the console produces no error though.

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Mon 01 Jun 2009 - 07:54:21 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 01 Jun 2009 - 12:34:29 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive