Skip to content
Back to formatted view

Raw Message

Message-ID: <2FB882D8-A0D0-4EB7-B899-78C75AF4A8AB@illinois.edu>
Date: 2020-10-23T13:32:42Z
From: Roger Koenker
Subject: formula mungeing

Suppose I have a formula like this:

	f <- y ~ qss(x, lambda = lambdas[1]) + qss(z, lambdas[2]) + s

I?d like a function, g(lambdas, f)  that would take g(c(2,3), f) and produce the new
formula:

	y ~ qss(x, lambda = 2) + qss(z, 3) + s

For only two qss terms I have been using 

	g <- function(lambdas, f){
		F <- deparse(f) 
		F <- gsub("lambdas\\[1\\]",lambdas[1],F)
		F <- gsub("lambdas\\[2\\]",lambdas[2],F)
		formula(F) 
	}
but this is ugly and doesn?t extend nicely to more qss terms.  Isn?t there some
bquote() magic that can be invoked?  Or something else entirely?