Yes, this is a very important point. Thank you, Bill.
Best, Ravi ________________________________ From: William Dunlap <[email protected]> Sent: Friday, February 13, 2015 4:56 PM To: Ravi Varadhan Cc: [email protected] Subject: Re: [R] Unable to use `eval(parse(text))' in nlme::lme > ff <- reformulate(termlabels=c("time","as.factor(gvhd)"), response=yname, > intercept=TRUE) If the right hand side of the formula were more complicated than an additive list of terms, say '~ time * as.factor(gvhd)' or the left side were more than a name, say 'log(yname)' you could use bquote() instead of reformulate. E.g., > formulaTemplate <- log(.(responseName)) ~ time * as.factor(gvhd) > lapply(c("y1","y2","y3"), function(yname)do.call(bquote, list(formulaTemplate, list(responseName=as.name<http://as.name>(yname))))) [[1]] log(y1) ~ time * as.factor(gvhd) [[2]] log(y2) ~ time * as.factor(gvhd) [[3]] log(y3) ~ time * as.factor(gvhd) I used 'do.call' because bquote does not evaluate its first argument, but we need to evaluate the name 'formulaTemplate'. You could avoid that by putting the template verbatim in the call to bquote, as in lapply(c("y1","y2","y3"), function(yname)bquote(log(.(responseName)) ~ time * as.factor(gvhd), list(responseName=as.name<http://as.name>(yname)))) I like the do.call method because I can bury it in a function and forget about it. bquote() retains the environment of the formula template. Bill Dunlap TIBCO Software wdunlap tibco.com<http://tibco.com> On Mon, Feb 9, 2015 at 6:44 AM, Ravi Varadhan <[email protected]<mailto:[email protected]>> wrote: Thanks to Rolf, Duncan, and Ben. Ben, your suggestion worked (with a minor correction of concatenating the termlabels into a vector). Here is the solution to those interested. ff <- reformulate(termlabels=c("time","as.factor(gvhd)"), response=yname, intercept=TRUE) dd <- subset(labdata2, Transplant_type!=0 & time >0) lme(ff, random=~1|Patient, data=dd, correlation=corAR1(), na.action=na.omit) Best, Ravi Ravi Varadhan, Ph.D. (Biostatistics), Ph.D. (Environmental Engg) Associate Professor Department of Oncology Division of Biostatistics & Bionformatics Johns Hopkins University 550 N. Broadway Baltimore, MD 21205 40-502-2619 [[alternative HTML version deleted]] ______________________________________________ [email protected]<mailto:[email protected]> mailing list -- To UNSUBSCRIBE and more, see 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. [[alternative HTML version deleted]] ______________________________________________ [email protected] mailing list -- To UNSUBSCRIBE and more, see 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.

