As workaround you can try this:

testlm <- function(formula, ...) {
 args <- list(formula, data = df1, ...)
 do.call(lm, args)
}

testlm(bmi ~ age, subset = df1$age > 50)



On Mon, Oct 25, 2010 at 2:16 AM, Erik Iverson <er...@ccbr.umn.edu> wrote:

> Hello,
>
> How would you go about handling the following situation?
> This is on R 2.12.0 on Ubuntu 32-bit.
>
> I have a wrapper function to lm.  I want to pass in a
> subset argument.  First, I just thought I'd use "...".
>
> ## make example reproducible
> set.seed(123)
> df1 <- data.frame(age = rnorm(100, 50, 10),
>                  bmi = rnorm(100, 30, sd = 2))
>
> ## create a wrapper using "..."
> testlm <- function(formula, ...) {
>  lm(formula, data = df1, ...)
> }
>
> > testlm(bmi ~ age, subset = age > 50)
>
> Error in eval(expr, envir, enclos) :
>  ..1 used in an incorrect context, no ... to look in
>
> I found some other examples of this error message,
> but couldn't piece together how it fits in with this
> example.
>
> Next, I tried specifying a subset argument.
>
> testlm2 <- function(formula, subset) {
>  lm(formula, data = df1, subset = subset)
> }
>
> > testlm2(bmi ~ age, subset = age > 50)
>
> Error in xj[i] : invalid subscript type 'closure'
>
> I also don't understand this one.
>
> Any pointers on if I'm just missing the easy
> solution to do what I want?  Any explanations
> as to the above behavior (I know it has to do
> with model.frame, but not sure how) would also
> be greatly appreciated!
>
> Thanks!
> --Erik
>
> ______________________________________________
> R-help@r-project.org 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org 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.

Reply via email to