I'm build a shiny app.
I need to query database based on user input. I guess I need to glue nothing into sql when user keep the default input values unchanged and glue something into the sql when user modify the default input values.
library(glue)
con <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
colnames(iris) <- gsub("[.]", "_", tolower(colnames(iris)))
DBI::dbWriteTable(con, "iris", iris)
empty <- NULL
value <- as.symbol("ORDER BY sepal_width")
glue_sql("SELECT * FROM iris {empty}", .con = con)
#> <SQL>
glue_sql("SELECT * FROM iris {value}", .con = con)
#> Warning in is.na(res): is.na() applied to non-(list or vector) of type
#> 'symbol'
#> <SQL> SELECT * FROM iris ORDER BY sepal_width
Created on 2019-04-12 by the reprex package (v0.2.1)