title: Convert string to symbol accepted by dplyr in function
body: <p>My data frame looks like:</p>
  
  <pre><code>&gt; str(b)
  'data.frame':   2720 obs. of  3 variables:
   $ Hospital.Name: chr  "SOUTHEAST ALABAMA MEDICAL CENTER" "MARSHALL MEDICAL CENTER SOUTH" "ELIZA COFFEE MEMORIAL HOSPITAL" "ST VINCENT'S EAST" ...
   $ State        : chr  "AL" "AL" "AL" "AL" ...
   $ heart attack : num  14.3 18.5 18.1 17.7 18 15.9 19.6 17.3 17.8 17.5 ...
  </code></pre>
  
  <p>I want to group it by State, sort them by State and Heart Attack, and then add a column that return row number within each group. The ideal result would look like:</p>
  
  <pre><code># A tibble: 2,720 x 4
  # Groups:   State [54]
                        Hospital.Name State `heart attack`  rank
                                &lt;chr&gt; &lt;chr&gt;          &lt;dbl&gt; &lt;int&gt;
   1 PROVIDENCE ALASKA MEDICAL CENTER    AK           13.4     1
   2         ALASKA REGIONAL HOSPITAL    AK           14.5     2
   3      FAIRBANKS MEMORIAL HOSPITAL    AK           15.5     3
   4     ALASKA NATIVE MEDICAL CENTER    AK           15.7     4
   5   MAT-SU REGIONAL MEDICAL CENTER    AK           17.7     5
   6         CRESTWOOD MEDICAL CENTER    AL           13.3     1
   7      BAPTIST MEDICAL CENTER EAST    AL           14.2     2
   8 SOUTHEAST ALABAMA MEDICAL CENTER    AL           14.3     3
   9               GEORGIANA HOSPITAL    AL           14.5     4
  10      PRATTVILLE BAPTIST HOSPITAL    AL           14.6     5
  # ... with 2,710 more rows
  </code></pre>
  
  <p>so my code is:</p>
  
  <pre><code>             outcome&lt;-"heart attack"
              c&lt;-arrange(b,State,sym(outcome))%&gt;%
                      group_by(State)%&gt;%
              mutate(rank=row_number(sym(outcome)))
  </code></pre>
  
  <p>but I got this error:</p>
  
  <pre><code>Error in arrange_impl(.data, dots) : object 'heart attack' not found
  </code></pre>
  
  <p>When I ran sym(outcome) independently and copied the results into my code, it works:</p>
  
  <pre><code>sym(outcome)
  `heart attack`
  c&lt;-arrange(b,State,`heart attack`)%&gt;%
  +                         group_by(State)%&gt;%
  +                 mutate(rank=rank(`heart attack`))
  &gt; c
  # A tibble: 2,720 x 4
  # Groups:   State [54]
                        Hospital.Name State `heart attack`  rank
                                &lt;chr&gt; &lt;chr&gt;          &lt;chr&gt; &lt;dbl&gt;
   1 PROVIDENCE ALASKA MEDICAL CENTER    AK           13.4     1
   2         ALASKA REGIONAL HOSPITAL    AK           14.5     2
   3      FAIRBANKS MEMORIAL HOSPITAL    AK           15.5     3
   4     ALASKA NATIVE MEDICAL CENTER    AK           15.7     4
   5   MAT-SU REGIONAL MEDICAL CENTER    AK           17.7     5
   6         CRESTWOOD MEDICAL CENTER    AL           13.3     1
   7      BAPTIST MEDICAL CENTER EAST    AL           14.2     2
   8 SOUTHEAST ALABAMA MEDICAL CENTER    AL           14.3     3
   9               GEORGIANA HOSPITAL    AL           14.5     4
  10      PRATTVILLE BAPTIST HOSPITAL    AL           14.6     5
  # ... with 2,710 more rows
  </code></pre>
  
  <p>This is a part of a function, so the 'outcome' needs to be a string. Therefore I tried to convert a string to a symbol so that I can reference the column in dplyr. 
  can anyone tell me what's happening here? 
  are there any good ways to achieve my goal?</p>