Skip to content
String interpolation to build regression formulas
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
R Bugfix Rd file Jan 10, 2020
man Bugfix Rd file Jan 10, 2020
.Rbuildignore First commit Jan 9, 2020
.gitignore First commit Jan 9, 2020
DESCRIPTION Bugfix Rd file Jan 10, 2020
NAMESPACE Bugfix Rd file Jan 10, 2020 Add drat installation to Github Jan 11, 2020
glueformula.Rproj Add varnames_snippet Jan 10, 2020

glueformula: string interpolation to build regression formulas

The main function is gl. It is a variant of glue to simplify building regression formulas given vectors of variable names.


# Example: build a formula for ivreg
# with gf

contr = c("x1","x2","x3") # exogenous control variables
instr = c(contr,"z1","z2") # instruments

gf(q ~ p + {contr} | {instr})

Another helper function is varnames_snippet. It just uses the colnames of a data frame to create a code snippet with a vector of all variable names. Here is an example:

df = dplyr::tibble(x=1,y=5,z=4,`a b`=4)

This prints (and on Windows copies to your clipboard) the following code snippet:

c("x", "y", "z", "`a b`")

You can then manually select the used variables in your regression by deleting the unused variables. With many variables, this can be much quicker than writing down all used variables.


The easiest way to install glueformula is from my Github powered package repository by running:

install.packages("glueformula",repos = c("",getOption("repos")))

Alteneratively, you can run the following code to install the source package from Github:

if (!require(glue)) install.packages("glue")
if (!require(remotes)) install.packages("remotes")

If the Github installation fails because unimportant warnings are converted to errors run before the installation:



You can’t perform that action at this time.