On Thu, 24 Nov 2011, Liviu Andronic wrote:
On Thu, Nov 24, 2011 at 10:25 PM, Prof Brian Ripley
<ripley at stats.ox.ac.uk> wrote:
Yes. ?That's a job for substitute (the second time today).
form <- formula(y1~x1)
x <- eval(substitute(lm(f, anscombe), list(f = form)))
summary(x)
Call:
lm(formula = y1 ~ x1, data = anscombe)
That's what I wanted. Thanks!
However, I do want to simplify the syntax and define a new function:
x.lm <-
?function(formula, data, ...)
{
?eval(substitute(lm(f, data, ...), list(f = formula)))
}
For the simple case it works just fine
x <- x.lm(form, anscombe)
But it fails when I try to input more lm() arguments:
(x <- x.lm(form, anscombe, subset=-5))
Error in eval(expr, envir, enclos) :
?..1 used in an incorrect context, no ... to look in
Am I doing something obviously wrong? Regards
Liviu
--
Brian D. Ripley, ? ? ? ? ? ? ? ? ?ripley at stats.ox.ac.uk
Professor of Applied Statistics, ?http://www.stats.ox.ac.uk/~ripley/
University of Oxford, ? ? ? ? ? ? Tel: ?+44 1865 272861 (self)
1 South Parks Road, ? ? ? ? ? ? ? ? ? ? +44 1865 272866 (PA)
Oxford OX1 3TG, UK ? ? ? ? ? ? ? ?Fax: ?+44 1865 272595