title: Passing arguments to functions, and variable scopes in R
body: <p>I'm writing a simple function that takes two arguments (state, outcome). State is used to subset a dataframe later.</p>
  
  <p>Having said that, part of the requirement is that state be a length 2 character vector. I need to write more code to ensure that the state that is passed conforms to this requirement.</p>
  
  <p>So I wrote the following:</p>
  
  <pre><code>best &lt;- function(state, outcome) {
  
    outcome &lt;- read.csv("outcome-of-care-measures.csv", colClasses = "character")
    state &lt;- vector(mode = "character", length = 2)
    st.checkTbl &lt;- outcome[8]
  
    state
    }
  </code></pre>
  
  <p>However, when I call the function and pass the arguments:</p>
  
  <pre><code>best("AXA") or best("FOO") or even best("TX") or best(AL)
  </code></pre>
  
  <p>All I get back is: "" ""</p>
  
  <p>If I comment out the #state &lt;- ... then it passes the argument just fine and it prints "FOO" or "AXA" or "TX", etc.</p>
  
  <p>How can I ensure that the argument passed to the function is stored as a variable (state) in the function? Or, am I way overthinking this? Really I just wanted to test that what I am passing to the state argument can be printed for test purposes.</p>
  
  <p>. Sorry for the 101 lesson.</p>