Skip to content
Prev 386086 / 398513 Next

formula mungeing

I can't compete with Gabor's "elegant" solution, but I don't understand why
your original "ugly" approach doesn't work.

g <- function(lambdas, f){
   z <- as.character(f)
   for(i in seq_along(lambdas))
      z[3]<-  sub(paste0("lambdas[", i, "]"), lambdas[i], z[3], fixed =
TRUE)
    formula(paste0(z[c(2,1,3)], collapse = " "))
}
y ~ qss(x, lambda = 1) + qss(z, 2) + s
<environment: 0x7f930e768598>
+     qss(z,lambdas[3]) + s
y ~ qss(x, lambda = 3) + qss(z, 2) + qss(z, 1) + s
<environment: 0x7f930e7404f0>

Is there maybe a problem with the environment of the created formula? Or
have I misunderstood what you wanted?

Cheers,
Bert

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Fri, Oct 23, 2020 at 6:33 AM Koenker, Roger W <rkoenker at illinois.edu>
wrote: