title: R tidyeval passing a list containing multiple character vectors to dplyr functions
body: <p>In this problem I want to map a function over multiple data inputs to create output showing frequencies of item responses.</p>
  
  <p>First I create two data sets using the <code>psych</code> package:</p>
  
  <pre><code>suppressMessages(library(here))
  suppressMessages(library(tidyverse))
  suppressMessages(library(psych))
  
  set.seed(123)
  
  data_input_sim &lt;-
    as_tibble(sim.poly.ideal(nvar = 50, n = 1000, cat = 4, )[["items"]]) %&gt;%
    mutate_all(
      ~ case_when(
        .x == 0 ~ "never",
        .x == 1 ~ "occasionally",
        .x == 2 ~ "frequently",
        .x == 3 ~ "always"
      )
    ) %&gt;%
    rename_all( ~ str_c("i", str_pad(
      as.character(1:50), 2, side = "left", pad = "0"
    ))) %&gt;%
    mutate(
      ID = 100001:101000,
      age = sample(c(5:12), 1000, replace = TRUE),
      age_range = case_when(
        age &lt;=8 ~ "5 to 8 yo",
        T ~ "9 to 12 yo"
      ),
      gender = sample(
        c("female", "male"),
        1000,
        replace = TRUE,
        prob = c(0.53, 0.47)
      ),
      educ = sample(
        c("no_HS", "HS_grad", "some_college", "BA_plus"),
        1000,
        replace = TRUE,
        prob = c(0.119, 0.263, 0.306, 0.311)
      ),
      ethnic = sample(
        c("hispanic", "asian", "black", "white", "other"),
        1000,
        replace = TRUE,
        prob = c(0.239, 0.048, 0.136, 0.521, .056)
      ),
      region = sample(
        c("northeast", "south", "midwest", "west"),
        1000,
        replace = TRUE,
        prob = c(0.166, 0.383, 0.212, 0.238)
      ),
      clin_status = sample(
        c("typ", "clin"),
        1000,
        replace = TRUE,
        prob = c(0.8, 0.2)
      )
    ) %&gt;%
    select(ID:clin_status, i01:i50)
  
  data_input_bfi &lt;- bfi %&gt;%
    drop_na() %&gt;%
    sample_n(1000) %&gt;%
    mutate(
      ID = 200001:201000,
      age_range = case_when(
        age &lt;= 18 ~ "18 yo or younger",
        between(age, 19, 24) ~ "19 to 24 yo",
        between(age, 25, 39) ~ "25 to 39 yo",
        T ~ "40 yo or older"
      ),
      gender = case_when(gender == 1 ~ "male",
                         gender == 2 ~ "female"),
      educ = case_when(
        education == 1 ~ "no_HS",
        education == 2 ~ "HS_grad",
        education == 3 ~ "some_college",
        T ~ "BA_plus"
      ),
      ethnic = sample(
        c("hispanic", "asian", "black", "white", "other"),
        1000,
        replace = TRUE,
        prob = c(0.239, 0.048, 0.136, 0.521, .056)
      ),
      region = sample(
        c("northeast", "south", "midwest", "west"),
        1000,
        replace = TRUE,
        prob = c(0.166, 0.383, 0.212, 0.238)
      ),
      clin_status = sample(
        c("typ", "clin"),
        1000,
        replace = TRUE,
        prob = c(0.8, 0.2)
      )
    ) %&gt;%
    mutate_at(
      vars(A1:O5),
      ~
        case_when(
          .x == 1 ~ "very_inaccurate",
          .x == 2 ~ "moderately_inaccurate",
          .x == 3 ~ "slightly_inaccurate",
          .x == 4 ~ "slightly_accurate",
          .x == 5 ~ "moderately_accurate",
          .x == 6 ~ "very_accurate",
        )
    ) %&gt;% 
    select(ID, age:clin_status, A1:O5)
  </code></pre>
  
  <p>Then I extract and sequence elements unique to each data set: the suffix of its name, the names of its item columns, and the names of its item categories:</p>
  
  <pre><code>data_name_suffix &lt;- c("sim", "bfi")
  
  sim_item_cols &lt;- str_c("i", str_pad(as.character(1:50), 2, side = "left", pad = "0"))
  bfi_item_cols &lt;- cross(list(c("A", "C", "E", "N", "O"), seq(1:5))) %&gt;%
    map_chr(str_c, collapse = "") %&gt;% 
    sort()
  
  sim_item_cats &lt;- c("never", "occasionally","frequently", "always")
  bfi_item_cats &lt;- c("very_inaccurate", "moderately_inaccurate", "slightly_inaccurate",
                    "slightly_accurate", "moderately_accurate", "very_accurate")
  </code></pre>
  
  <p><code>data_name_suffix</code> is a two-element character vector; I then create two-element lists (using <code>quos()</code>) to hold the item column and category names:</p>
  
  <pre><code>item_cols &lt;- quos(sim_item_cols, bfi_item_cols)
  item_cats &lt;- quos(sim_item_cats, bfi_item_cats)
  </code></pre>
  
  <p>Now I attempt to map the output-creating function over the three inputs, using <code>purrr::pmap()</code>:</p>
  
  <pre><code>pmap_df(
    list(data_name_suffix,
         item_cols,
         item_cats),
    ~
      eval(as.name(str_c("data_input_", data_name_suffix))) %&gt;%
      select(!!!item_cols) %&gt;%
      gather(var, value) %&gt;%
      group_by(var, value) %&gt;%
      count(var, value) %&gt;%
      ungroup() %&gt;%
      spread(value, n) %&gt;%
      arrange(match(var, !!!item_cols)) %&gt;%
      select(var, !!!item_cats) %&gt;% 
      assign(str_c("freq_item_val_", data_name_suffix), ., envir = .GlobalEnv)
  )
  </code></pre>
  
  <p>And it returns this error:</p>
  
  <pre><code>Error: Unknown columns `A1`, `A2`, `A3`, `A4`, `A5` and ... 
  </code></pre>
  
  <p>Which suggests to me that R is seeing the list <code>item_cols</code> as a single long character vector, rather than two separate character vectors to iterate over.</p>
  
  <p>And here we reach the limit of my understanding of and experience with <code>tidyeval</code> techniques. I suspect that I'm doing something wrong with <code>quos()</code> and <code>!!!</code>.</p>
  
  <p>Thanks in advance for any help, and I hope whoever reads this is safe and healthy during this surreal time.</p>