title: programming with dplyr- how to deal with quotes/enquotes
body: <p>I need to create a wrapper function that executes a database call with <code>dplyr</code>. </p>
  
  <p>First create a reproducible example:</p>
  
  <pre><code>library("DBI")
  library("dplyr")
  conn = DBI::dbConnect(RSQLite::SQLite(), path = ":memory:")
  
  df = expand.grid(indate = as.character(as.POSIXct(seq(as.Date('2017/06/06'), as.Date('2018/02/12'), by="day"))), name = c("Canada","Japan","USA"), stringsAsFactors = FALSE)
  
  copy_to(conn, df, "lineups_country",
          temporary = FALSE, 
          indexes = list(
            "indate",
            "name"
          )
  )
  </code></pre>
  
  <p>This is the code that works well without the wrapper function:</p>
  
  <pre><code>res = tbl(conn, table)
  
  # filter the country
  res = res %&gt;% filter(name %in% c("Canada","Japan"))
  
  # filter the date
  res = res %&gt;% filter(indate &gt;= "2018-01-01")
  
  res %&gt;% show_query()
  df2=res %&gt;% collect()
  unique(df$name);unique(df2$name)
  min(df$indate);min(df2$indate)
  </code></pre>
  
  <p>Now to create the wrapper function, I have read the document <a href="https://cran.r-project.org/web/packages/dplyr/vignettes/programming.html" rel="nofollow noreferrer">https://cran.r-project.org/web/packages/dplyr/vignettes/programming.html</a></p>
  
  <p>However things are far from clear to me, especially regarding the quotes/enquotes.</p>
  
  <p>here is what I tried:</p>
  
  <pre><code>myFun = function(conn, table, 
                   dateCol   = "indate", 
                   startDate = as.POSIXct("2018-01-01"), 
                   key       = list(name = c("Australia","Japan"))) {
  
  
    on.exit({dbDisconnect(conn)})
    res = tbl(conn, table) 
  
    res %&gt;% show_query()
  
    # filter the country
    countryCol = names(key)
    enquo_country &lt;- enquo(countryCol) #enquo_country &lt;- rlang::sym(countryCol) #
    res = res %&gt;% filter(!!enquo_country %in% key[[1]])
  
    res %&gt;% show_query()
  
    # filter the date
    enquo_dateCol &lt;- enquo(dateCol) #enquo_country &lt;- rlang::sym(names(key)) #
    res = res %&gt;% filter(!!enquo_dateCol &gt;= as.character(startDate))
  
    res %&gt;% show_query()
  
    return(res %&gt;% collect())
  }
  </code></pre>
  
  <p>which gives an error: </p>
  
  <blockquote>
    <p>Error in match(x, table, nomatch = 0L) :    'match' requires vector
    arguments</p>
  </blockquote>