Skip to content

# skranz / glueformula

String interpolation to build regression formulas
R
Latest commit 896867c Jan 11, 2020
Type Name Latest commit message Commit time
Failed to load latest commit information.
R Jan 10, 2020
man Jan 10, 2020
.Rbuildignore Jan 9, 2020
.gitignore Jan 9, 2020
DESCRIPTION Jan 10, 2020
NAMESPACE Jan 10, 2020
README.md Jan 11, 2020
glueformula.Rproj 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.

```library(glueformula)

# 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)
varnames_snippet(df)
``````

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.

### Installation

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

`install.packages("glueformula",repos = c("https://skranz-repo.github.io/drat/",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")
remotes::install_github("skranz/glueformula")
``````

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

`Sys.setenv(R_REMOTES_NO_ERRORS_FROM_WARNINGS="true")`
You can’t perform that action at this time.