Skip to content
Prev 248123 / 398525 Next

Passing in arguments into function

Hi Paul,

You need to pass the formula object, not a string.  If you have a
function that is passing one of its arguments down to lm(), just pass
the argument directly, no need to do anything special.  Here are some
examples using a built in dataset:

## wrapper function
foo <- function(fooform, ...) {
  summary(lm(formula = fooform, ...))
}

## seeing it in action
foo(mpg ~ hp * wt, data = mtcars)

## save a formula in an object
myform <- mpg ~ hp * wt

## pass the object to foo() which passes it down
foo(myform, data = mtcars)

## pass the formula object "myform" directly to lm()
summary(lm(myform, data = mtcars))

Do one of those answer your question or do what you want?

Hope this helps,

Josh
On Sun, Jan 23, 2011 at 8:46 AM, Paul Evans <p.evans48 at yahoo.com> wrote: