title: Using purrr::map2() with dbplyr
body: <p>I'm trying to select lines from one table ("positons") with values for a particular column ("position") that fall within the ranges defined in another ("my_ranges") table, and then to add a grouping tag from the "my_ranges" table.</p>
  
  <p>I can do this using tibbles and a couple <code>purrr::map2</code> calls, but the same approach doesn't work with dbplyr database-tibbles. Is this expected behavior, and if so, is there a different approach that I should take to use dbplyr for this kind of task?</p>
  
  <p>Here's my example:</p>
  
  <pre><code>library("tidyverse")
  set.seed(42)
  
  my_ranges &lt;-
    tibble(
      group_id = c("a", "b", "c", "d"),
      start = c(1, 7, 2, 25),
      end = c(5, 23, 7, 29)
      )
  
  positions &lt;-
    tibble(
      position = as.integer(runif(n = 100, min = 0, max = 30)),
      annotation = stringi::stri_rand_strings(n = 100, length = 10)
    )
  
  # note: this works as I expect and returns a tibble with 106 obs of 3 variables:
  result &lt;- map2(.x = my_ranges$start, .y = my_ranges$end,
               .f = function(x, y) {between(positions$position, x, y)}) %&gt;%
    map2(.y = my_ranges$group_id,
                .f = function(x, y){
                  positions %&gt;%
                    filter(x) %&gt;%
                    mutate(group_id = y)}
  ) %&gt;% bind_rows()
  
  # next, make an in-memory db for testing:
  con &lt;- DBI::dbConnect(RSQLite::SQLite(), path = ":memory:")
  
  # copy data to db
  copy_to(con, my_ranges, "my_ranges", temporary = FALSE)
  copy_to(con, positions, "positions", temporary = FALSE)
  
  # get db-backed tibbles:
  my_ranges_db &lt;- tbl(con, "my_ranges")
  positions_db &lt;- tbl(con, "positions")
  
  # note: this does not work as I expect, and instead returns a tibble with 0 obsevations of 0 variables:
  # database range-based query:
  db_result &lt;- map2(.x = my_ranges_db$start, .y = my_ranges_db$end,
                    .f = function(x, y) {
                      between(positions_db$position, x, y)
                      }) %&gt;%
    map2(.y = my_ranges_db$group_id,
         .f = function(x, y){
           positions_db %&gt;%
             filter(x) %&gt;%
             mutate(group_id = y)}
    ) %&gt;% bind_rows()
  </code></pre>