Thanks, Mick and Greg. Greg, I have one doubt: taking into account that scope is the cause and that I need to pass a data.frame in the data of the lm, why does it run in some machines?. That point is the one I do not understand. In any case, I made the change (data.frame) and it will be tested. Cheers, Eva --- El jue, 1/11/12, Greg Snow <[email protected]> escribió:
De: Greg Snow <[email protected]> Asunto: Re: [R] Problem with lm Para: "Mick Cooney" <[email protected]> CC: "Eva Prieto Castro" <[email protected]>, [email protected] Fecha: jueves, 1 de noviembre, 2012 17:49 This error can still occur even if something is passed as the y parameter to the function. There are several things that can complicate the process (and I don't remember exactly which one causes the problem in this case). Here are a couple: In the original function, y is a parameter, but it is never actually used before the call to lm, which means that y is really a promise to evaluate whatever was passed to the function, but does not yet contain the actual y values. The lm function calls the model.frame function which calls the model.frame.default function, which may call another function, which of all those function environments should it look for the variable y in? (it seems obvious to us, but the computer is not as smart), there is also the environment that the formula was defined in that is used for some things. Possibly others as well. In either case if an explicit data frame is created (which will force the evaluation of the promise for y) and passed to the data argument of lm, then all these functions know exactly where to look to find the variables in the formula and don't need to worry about parent frames and parent environments. This document: http://developer.r-project.org/nonstandard-eval.pdf gives more detail. On Thu, Nov 1, 2012 at 10:23 AM, Mick Cooney <[email protected]> wrote: > But the 'y' is a parameter to the function, so does this mean that the > error is occurring when the function is invoked without that > parameter? > > On 1 November 2012 16:02, Greg Snow <[email protected]> wrote: >> Yes, it is most likely due to scoping. It is safest to create a data >> frame with all the data in it, then pass that to the data argument of >> lm. >> >> On Thu, Nov 1, 2012 at 2:25 AM, Eva Prieto Castro <[email protected]> >> wrote: >>> Hi, >>> >>> I have a problem in relation with a packahe I made. It runs on my machine >>> (Windows, where I made the package), and it runs in a Mac machine, but it >>> does not run in another Mac machine with the same R version. >>> >>> The part of the code is giving problems: >>> >>> singleCosinor <- function(t, y, period=24) { >>> x1 <- cos(2 * pi * t / period) >>> x2 <- sin(2 * pi * t / period) >>> single <- lm (y ~ x1 + x2) >>> return(single) >>> } >>> >>> The error: >>> >>> Error en eval(expr, envir, enclos) : objeto 'y' no encontrado >>> >>> Can it be in relation with scoping?. >>> >>> Thanks in advance. >>> >>> Eva >>> >>> [[alternative HTML version deleted]] >>> >>> >>> ______________________________________________ >>> [email protected] mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >>> >> >> >> >> -- >> Gregory (Greg) L. Snow Ph.D. >> [email protected] >> >> ______________________________________________ >> [email protected] mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > > > -- > Mick Cooney > [email protected] -- Gregory (Greg) L. Snow Ph.D. [email protected] [[alternative HTML version deleted]]
______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.

