title: Enum-like arguments in R
body: <p>I'm new to R and I'm currently trying to supply the enumeration-like argument to the R function (or the RC/R6 class method), I currently use character vector plus <code>match.arg</code> similar to the following:</p>
  
  <pre><code>EnumTest = function(enum = c("BLUE", "RED", "BLACK")) {
    enumArg &lt;-
      switch(
        match.arg(enum), "BLUE" = 0L, "RED" = 1L, "BLACK" = 2L
      )
    switch(enumArg,
           # do something
    )
  }
  </code></pre>
  
  <p>Is there are better/more concise way to imitate enum-like behavior in R? E.g. one big problem that user has to know the set of possible values for the argument and manually type it as a string - without any suggestion or auto-completion...</p>
  
  <p>If there is no other better way, one thing that could improve above approach - it'd be nice to make it more concise by say predefining enums globally or say as private members of R6 class:</p>
  
  <pre><code>Color &lt;- c("BLUE", "RED", "BLACK")
  </code></pre>
  
  <p>Then one could (re)use it in one or more function definitions, e.g.:</p>
  
  <pre><code>EnumTest = function(enum = Color) { 
  ...
  </code></pre>
  
  <p>However, I'm not sure how to use this <code>Color</code> vector in <code>match.arg</code> function. It'd be nice if I could define <code>Color</code> as a map with keys being actual color values and values being integer representation - but I'm not sure how sensible that is.. Anyways, maybe there are more common neat approaches exist.</p>
  
  <p>The main goal would be to provide an easy-to-use intuitive interface to the user of my package and functions (e.g. easy way to find the set of possible values, tab-completion, auto-suggestion, etc..), followed by standardized development of such functions using enum-like arguments</p>