I am looking for an easy way to have my function work with input the comes from Shiny
(i.e. string input) or with typical interactive use that is Tidyverse
functions enable with NSE. Without the need to duplicate my code to handle each case separately.
An example of usage:
library(dplyr)
flexible_input <- function(var){
mtcars %>%
select(var)
}
# This works for NSE
nse_input <- function(var){
mtcars %>%
select({{ var }})
}
# This works for shiny but now I am duplicated my code essentially
shiny_input <- function(var){
mtcars %>%
select(.data[[var]])
}
flexible_input(mpg)
flexible_input('mpg')