title: R retrieving values from data.tables while within custom functions
body: <p>I'm trying to retrive a value from a datatable as part of a larger custom function. I can gnerate the row number, but I can't retrive the values from that row. The formula works outside of the function environment but not inside.</p>
  <pre><code>example_outlier_table &lt;- data.table(dataset = c(&quot;doe&quot;, &quot;ray&quot;, &quot;me&quot;, &quot;fa&quot;, &quot;so&quot;),
                                      upper_limit = c(2,6,9,11,7))
  
  example_function &lt;- function(dt,otable){
    return(match(deparse(substitute(dt)), otable$dataset))
  }
  
  example_function(ray, example_outlier_table)
  </code></pre>
  <p>result = 2</p>
  <p>This is correct, 'ray' is the second entry in the 'dataset' column</p>
  <p>In this example, 'ray' is both the character string in 'example_outlier_table$dataset' and the name of another data table object, hence the  'deparse(substitute(dt))' step.</p>
  <p>The issue is this: I want to use the value that 'ray' indicates in the example_outlier_table, number 6, in another place within my custom function.</p>
  <pre><code>example_function &lt;- function(dt,otable){
    return(otable[dataset == as.character(deparse(substitute(dt))), 
                  upper_limit])
  }
  
  example_function(ray, example_outlier_table)
  </code></pre>
  <p>result = numeric(0)
  incorrect</p>
  <pre><code>example_function &lt;- function(dt,otable){
    return(otable[match(deparse(substitute(dt)), otable$dataset), 
                  upper_limit])
  }
  
  example_function(ray, example_outlier_table)
  </code></pre>
  <p>result = [1] NA</p>