formula_utils.Rd
Tools to create R formulas
g3_formula(code, ...)
When using ~
, the local environment is attached to the code.
This can leak unwanted variables into a model. This allows you to avoid
the problem without resorting to local.
A formula object, with environment created from .... Can then be used anywhere in gadget3 that accepts a formula.
# g3_formula is identical to defining a formula within local():
stopifnot(all.equal(
g3_formula(x + 1, z = 44),
local({ z = 44; ~x + 1 })
))
# If the code is destined for CRAN, you need to quote() to avoid check errors:
stopifnot(all.equal(
g3_formula(quote( x + 1 ), z = 44),
local({ z = 44; ~x + 1 })
))