interp: Interpolate values into an expression.

Description Usage Arguments Examples

Description

This is useful if you want to build an expression up from a mixture of constants and variables.

Usage

1
interp(`_obj`, ..., .values)

Arguments

_obj

An object to modify: can be a call, name, formula, lazy, or a string.

..., .values

Either individual name-value pairs, or a list (or environment) of values.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Interp works with formulas, lazy objects, quoted calls and strings
interp(~ x + y, x = 10)
interp(lazy(x + y), x = 10)
interp(quote(x + y), x = 10)
interp("x + y", x = 10)

# Use as.name if you have a character string that gives a
# variable name
interp(~ mean(var), var = as.name("mpg"))
# or supply the quoted name directly
interp(~ mean(var), var = quote(mpg))

# Or a function!
interp(~ f(a, b), f = as.name("+"))
# Remember every action in R is a function call:
# http://adv-r.had.co.nz/Functions.html#all-calls

# If you've built up a list of values through some other
# mechanism, use .values
interp(~ x + y, .values = list(x = 10))

# You can also interpolate variables defined in the current
# environment, but this is a little risky.
y <- 10
interp(~ x + y, .values = environment())

Example output

~10 + y
<lazy>
  expr: 10 + y
  env:  <environment: R_GlobalEnv>
10 + y
[1] "10 + y"
~mean(mpg)
~mean(mpg)
~a + b
~10 + y
~x + 10

lazyeval documentation built on May 2, 2019, 2:11 a.m.