wrapr::let() is designed to get several important corner cases correct: including substitutions that are disjoint from the expression and symbol swaps.
library("wrapr")
X <- 1
Y <- 2
let(
c(),
debugPrint = TRUE,
X + Y
)## X + Y
## [1] 3
let(
c(),
debugPrint = TRUE,
subsMethod = 'langsubs',
X + Y
)## X + Y
## [1] 3
let(
c(),
debugPrint = TRUE,
subsMethod = 'stringsubs',
X + Y
)## X + Y
## [1] 3
let(
c(),
debugPrint = TRUE,
subsMethod = 'subsubs',
X + Y
)## X + Y
## [1] 3
library("wrapr")
X <- 1
Y <- 2
let(
c(X='Y', Y='X'),
debugPrint = TRUE,
X + Y
)## Y + X
## [1] 3
let(
c(X='Y', Y='X'),
debugPrint = TRUE,
subsMethod = 'langsubs',
X + Y
)## Y + X
## [1] 3
let(
c(X='Y', Y='X'),
debugPrint = TRUE,
subsMethod = 'stringsubs',
X + Y
)## expression(Y + X)
## [1] 3
let(
c(X='Y', Y='X'),
debugPrint = TRUE,
subsMethod = 'subsubs',
X + Y
)## Y + X
## [1] 3