title: Reorder a column of a dataframe by factor() and using variable from argparse
body: <p>I am using <a href="https://github.com/trevorld/r-argparse" rel="nofollow noreferrer">argparse</a> library to build a boxplot with <a href="https://github.com/kassambara/ggpubr" rel="nofollow noreferrer">ggpubr</a> library from command line interface. I can reorder particular column of my interest manually. 
  However, I want to reorder particular column using argparse. 
  I cannot figure it out, how to use <strong>df$args$reorder</strong> name.</p>
  
  <p>Somehow, I need to automatize the line</p>
  
  <pre><code>df$Population &lt;- factor(df$Population, levels = c("Control", "American"))
  </code></pre>
  
  <p>to</p>
  
  <pre><code>get(args$reorder, df) &lt;- factor(get(args$reorder, df), levels = c(args$new_order))
  </code></pre>
  
  <p>or</p>
  
  <pre><code>df$args$reorder &lt;- factor(df$args$reorder, levels = c(args$new_order)
  </code></pre>
  
  <p>Here is the code I have tried</p>
  
  <pre><code>#!/usr/local/bin/Rscript
  
  suppressWarnings(library(argparse))
  suppressWarnings(library(ggpubr))
  
  parser &lt;- ArgumentParser(description="Tools for making plot from command line") 
  
  parser$add_argument("--file", type="character", help="Input file")
  parser$add_argument("--x-ax", type="character", help="x_axis value")
  parser$add_argument("--y-ax", type="character", help="y_axis value")
  parser$add_argument("--color", type="character", help="color by")
  parser$add_argument("--facet-col", type="character", default=NULL, help="facet by")
  parser$add_argument("--reorder", type="character", default=NULL, help="reorder a column")
  parser$add_argument("--new_order", type="character", default=NULL, help="new orders for the items")
  
  args &lt;- parser$parse_args()
  
  df &lt;- read.csv(args$file)
  
  head(df)
  #Population  Diet BloodPressure
  #1   American Vegan           167
  #2   American Vegan           160
  #3   American Vegan           162
  #4   American Vegan           165
  #5   American Vegan           159
  #6   American Vegan           177
  
  #The line below can manually reorder the items in the column.
  #df$Population &lt;- factor(df$Population, levels = c("Control", "American"))
  
  # I want to do something like this
  #get(args$reorder, df) &lt;- factor(get(args$reorder, df), levels = c(args$new_order))
  
  
  fig &lt;- ggboxplot(df, x = args$x_ax , y = args$y_ax, 
  facet.by = args$facet_col, fill = args$color, palette = "npg")
  
  ggsave("reorder_factor.png")
  </code></pre>
  
  <p>The data I used is <a href="http://freetexthost.com/h6rgknc32w" rel="nofollow noreferrer">here</a></p>
  
  <p>Before reordering the <a href="https://i.postimg.cc/JnfvLngJ/reorder-factor.png" rel="nofollow noreferrer">image is like the following</a></p>
  
  <p>and after reordering <a href="https://i.postimg.cc/4yRL007Q/reorder-factor.png" rel="nofollow noreferrer">image is like following</a></p>