Hi,
I solved as follws:
 f <- formula(y ~ x1 + x2)
 single <- do.call("lm", list(f, data=mydf))
It works in every machine!!.
Thanks and I'm sorry if I did not answer all your responses about this question.
Cheers,
Eva
--- El vie, 2/11/12, Eva Prieto Castro <[email protected]> escribió:
De: Eva Prieto Castro <[email protected]>
Asunto: RE: [R] Problem with lm
Para: "Mick Cooney" <[email protected]>, "Greg Snow" <[email protected]>,
"William Dunlap" <[email protected]>
CC: "[email protected]" <[email protected]>
Fecha: viernes, 2 de noviembre, 2012 09:47
Hi everybody,
I send you
two test I made (without data.frame and with data.frame). In two cases the
problem is with the formula.
Â
Obs.: As I
said you, there are two machines in which the package runs ok, and another one
in which it returns this error I send you. It is a very important for me the
fact of tell you that the use of the function singleCosinor is made with the
same data values (t, ySC, period) in tests in the three machines, so I
donât know if
we are with a programming problem or if there is something wrong in the machine
in which the package fails.
Â
singleCosinor <- function(t, ySC, period=24)
{
 x1
<- cos(2 * pi * t / period)
 x2
<- sin(2 * pi * t / period)
Â
formulaSC <- as.formula("ySC ~ x1 + x2")
Â
environment(formulaSC) <- environment()
 single
<- lm(formulaSC)
Â
return(single)
}
Â
Error en
model.frame(formula = formulaSC, na.action = "na.exclude",
drop.unused.levels = TRUE) :
 objeto 'formulaSC' no encontrado
Â
>
traceback()
Â
19:
model.frame(formula = formulaSC, na.action = "na.exclude",
drop.unused.levels = TRUE)
18:
eval(expr, envir, enclos)
17:
eval(mf, parent.frame())
16: lm(formula = formulaSC, na.action =
"na.exclude")
15:
eval(expr, envir, enclos)
14:
eval(call, parent.frame())
13:
update.default(model, na.action = "na.exclude")
12:
update(model, na.action = "na.exclude")
11:
ncvTest.lm(resLM)
10:
ncvTest(resLM)
9:
format(round(value, numdec), nsmall = numdec, scientific = FALSE)
8:
RoundDec(ncvTest(resLM)$p, 3)
7:
regressionTest.Hom(resul)
6:
FUN(newX[, i], ...)
5:
apply(dfIniChronoRegression, 1, AnalisisRitmometrico, rS$lSeries,
      rS$bRegressionTest, bBingham,
rS$nConfLevel, rS$bExisteFund)
4: analyze.
MyPkt_Single(MyPkt.env$lGlo)
3:
analyze(.MyPkt.env$lGlo)
2: RS()
1: MyPkt.RS()
Â
Â
Â
Â
singleCosinor <- function(t, ySC, period=24)
{
 myx1
<- cos(2 * pi * t / period)
 myx2
<- sin(2 * pi * t / period)
 mydf
<- data.frame(x1=myx1,x2=myx2,y=ySC)
 formulaSC
<- as.formula("y ~ x1 + x2")
 environment(formulaSC) <-
environment()
 single
<- lm(formulaSC, data=mydf)
 return(single)
}
Â
Error en model.frame(formula = formulaSC, data = mydf,
na.action = "na.exclude", :
 objeto 'formulaSC'
no encontrado
Â
> traceback()
Â
19:
model.frame(formula = formulaSC, data = mydf, na.action =
"na.exclude",
       drop.unused.levels = TRUE)
18:
eval(expr, envir, enclos)
17:
eval(mf, parent.frame())
16: lm(formula = formulaSC, data = mydf,
na.action = "na.exclude")
15:
eval(expr, envir, enclos)
14:
eval(call, parent.frame())
13:
update.default(model, na.action = "na.exclude")
12:
update(model, na.action = "na.exclude")
11:
ncvTest.lm(resLM)
10: ncvTest(resLM)
9:
format(round(value, numdec), nsmall = numdec, scientific = FALSE)
8:
RoundDec(ncvTest(resLM)$p, 3)
7:
regressionTest.Hom(resul)
6:
FUN(newX[, i], ...)5: apply(dfIniChronoRegression, 1, AnalisisRitmometrico,
rS$lSeries,
      rS$bRegressionTest, bBingham,
rS$nConfLevel, rS$bExisteFund)
4: analyze.
MyPkt_Single(MyPkt.env$lGlo)
3:
analyze(.MyPkt.env$lGlo)
2: RS()
1: MyPkt.RS()
Â
 I hope you can put some light in this question, because I am very confused.
Thanks in advance.
Â
Cheers,
Eva
--- El vie, 2/11/12, William Dunlap <[email protected]> escribió:
De: William Dunlap <[email protected]>
Asunto: RE: [R] Problem with lm
Para: "Eva Prieto Castro" <[email protected]>, "Mick Cooney"
<[email protected]>, "Greg Snow" <[email protected]>
CC: "[email protected]" <[email protected]>
Fecha: viernes, 2 de noviembre, 2012 00:53
Did you ever show us the call to your function that made it fail
on one machine and succeed on two others? In addition, seeing
the output of traceback() after the failure and the output of
sessionInfo() and conflicts() would help track down the problem.Â
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
> -----Original Message-----
> From:
[email protected] [mailto:[email protected]] On Behalf
> Of Eva Prieto Castro
> Sent: Thursday, November 01, 2012 2:59 PM
> To: Mick Cooney; Greg Snow
> Cc: [email protected]
> Subject: Re: [R] Problem with lm
>
>
> 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]]
[[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.