[R] Passing variable names as function arguments for lme model specification

From: <jmlange_at_ucla.edu>
Date: Tue, 08 May 2007 21:47:49 -0700


Hello,

I have what I hope is a relatively straightforward question.

I'm trying to write a function that runs lme using variables specified in the function argument, along with some other tasks.

However, I'm having some problems with lme accessing the variables I'm interested in.

Here's a simplified version of my test code:

testfunction<-function(var1, var2)
{

lme(var1 ~ var2,random=~1,data=testdata) #other stuff...
}

If I run testfunction(var_a, var_b), I get the following error: Error in model.frame(formula, rownames, variables, varnames, extras, extranames, :

         invalid variable type

I tested the same procedure with lm rather than lme, and it seems to be an acceptable way of passing arguments with this procedure.

This works:
testfunction<-function(var1, var2)
{

lm(var1 ~ var2,data=testdata)
#other stuff...
}

Any help on this matter would be much appreciated,

Jane Lange
Department of Biostatistics, UCLA



R-help_at_stat.math.ethz.ch 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. Received on Wed 09 May 2007 - 04:52:18 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 09 May 2007 - 05:31:42 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.