title: Arrange by custom order in dplyr using dynamic column names
body: <p>I am trying to arrange a tibble based on a certain column (but setting the column based on a name dynamically set by a variable).</p>
  
  <p>Below is the code I currently am trying but am getting an error. The second paste of code works (where I have hard coded in the column name of symbol which I want to be set based off of a variable instead).</p>
  
  <pre><code>library(tidyverse)
  
  group_var &lt;- "symbol"
  
  date_seq &lt;- seq(as.Date("2000-01-01"), as.Date("2009-12-31"), by = "days")
  test_tbl &lt;- tibble::tibble("date" = rep(date_seq, 3),
                             "symbol" = rep(c("test3", "test1", "test2"), each = length(date_seq)),
                             "value" = c(rnorm(length(date_seq), sd = 0.05),
                                         rnorm(length(date_seq), sd = 0.05),
                                         rnorm(length(date_seq), sd = 0.05)))
  
  order_var &lt;- c("test1", "test2", "test3")
  test_tbl_final &lt;- test_tbl %&gt;%
    dplyr::arrange(factor(!!group_var, levels = order_var), date)
  </code></pre>
  
  <p>Below is the code that works and shows what I am trying to accomplish:</p>
  
  <pre><code>library(tidyverse)
  
  date_seq &lt;- seq(as.Date("2000-01-01"), as.Date("2009-12-31"), by = "days")
  test_tbl &lt;- tibble::tibble("date" = rep(date_seq, 3),
                             "symbol" = rep(c("test3", "test1", "test2"), each = length(date_seq)),
                             "value" = c(rnorm(length(date_seq), sd = 0.05),
                                         rnorm(length(date_seq), sd = 0.05),
                                         rnorm(length(date_seq), sd = 0.05)))
  
  order_var &lt;- c("test1", "test2", "test3")
  test_tbl_final &lt;- test_tbl %&gt;%
    dplyr::arrange(factor(symbol, levels = order_var), date)
  </code></pre>