I am confused. Richard's answer that Bert did not like did not use parse explicitly. Richard pasted together a string that a function like lm() will have to parse to run the analysis. However, the answers so far do not use parse(). In the reply to Richard, Bert indicated we cannot use strings. Even if I pass a vector where R can assume that the first variable is the dependent variable and all others are independent variables, I see no way of processing that within the current modeling system without generating a formula (a string) that gets parsed.
-----Original Message----- From: R-help <[email protected]> On Behalf Of Richard M. Heiberger Sent: Saturday, March 29, 2025 8:47 PM To: Bert Gunter <[email protected]> Cc: R-help <[email protected]> Subject: Re: [R] [External] Creating model formulas programmatically [External Email] my take of the assignment was to avoid 'parse' specifically. we start with a character vector, so avoiding characters is not possible. i was dealing with the fortune "if parse is the answer, you have the wrong question" Sent from my iPhone On Mar 29, 2025, at 15:39, Bert Gunter <[email protected]> wrote: Thanks, Rich. I thought of that, too, but it violates the spirit of my restraints (to avoid character strings), which I unfortunately did not clearly articulate. So my apologies for that failure. My concern is that with more complex model formula, using as.formula, etc. to parse/convert character strings can get a bit hairy. But in most cases, as here maybe, it may be perfectly fine. So think of my post as mostly my attempt to learn some new tricks rather than to solve a useful problem. I hope this is not unfair to the list. Cheers, Bert On Sat, Mar 29, 2025 at 3:1 PM Richard M. Heiberger <[email protected]<mailto:[email protected]>> wrote: > somenames <- c("Heigh", "Ho", "Silver", "Away") > as.formula(paste("~(",paste(somenames, collapse="+"),")^2")) ~(Heigh + Ho + Silver + Away)^2 > > On Mar 29, 2025, at 14:30, Bert Gunter > <[email protected]<mailto:[email protected]>> wrote: > > somenames <- c("Heigh", "Ho", "Silver", "Away") [[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 https://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ______________________________________________ [email protected] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide https://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.

