title: Function works normally. But when used with sapply in order to pass each value of a vector as one of the arguments, I get an error
body: <p>Sorry for the bad phrasing of the question!</p>
  <p>I created a function, abc, and it works fine with my data table, DT, by itself.</p>
  <pre><code>#function
  abc &lt;- function(DT, ucol=&quot;u&quot;, vcol=&quot;v&quot;, xdiff = 3) {
    #find n
    result1 = DT[DT[,x2:= x_coord. + xdiff ], on=.(y_coord, x_coord=x2), nomatch=0]
    result1[, ucol_values:=get(ucol)]
    n_points &lt;- nrow(result1)                   #N
    
    #find (ui-uj)*(vi-vj)
    result2 = result1
    result[, prod:=(get(ucol)-get(paste0(&quot;i.&quot;,ucol)))*(get(vcol)-get(paste0(&quot;i.&quot;,vcol)))][, .(row_a=row, row_b=i.row, prod)]
    sum_prod_result&lt;- sum(result2$prod)
      
    resultlist&lt;- list(&quot;xdiff&quot;=xdiff, &quot;sum of products&quot;=sum_prod_result, &quot;n&quot;=n_points)
    
    return(resultlist)
  }
  
  &gt;abc(DT)
  $`xdiff`
  [1] 5
  
  $`sum of products`
  [1] -0.731064
  
  $n
  [1] 43
  </code></pre>
  <p>I have a vector x and I want to repeat the function with xdiff equal to each value of x.</p>
  <pre><code>x &lt;- (5,10,15,20,25)
  
  sapply&lt;- (xdiffs, abc, xdiff=x)
  
  </code></pre>
  <p>But I get the following error with sapply:</p>
  <p>Error in <code>:=</code>(x2, x_coord. + xdiff) :
  Check that is.data.table(DT) == TRUE. Otherwise, := and <code>:=</code>(...) are defined for use in j, once only and in particular ways. See help(&quot;:=&quot;).</p>
  <p>I checked the class of DT and it is a data table. I'm not sure how to fix this issue.</p>