title: About Error ":= and `:=`(...) are defined for use in j, once only and in particular ways. See help(":=")"
body: <p>I encountered a weird error message in data.table</p>
  
  <p>I modified a data.table using <code>:=</code> , and it is totally OK without any error.
  When I trying to put the code into a function, the following error message comes out. </p>
  
  <pre><code>Error in `:=`(date, as.Date(as.character(date), "%Y%m%d") - 1) : 
  := and `:=`(...) are defined for use in j, once only and in particular ways. See     help(":="). Check is.data.table(DT) is TRUE.
  </code></pre>
  
  <p>Here's reproducible example </p>
  
  <pre><code>testdat &lt;- data.table(ID = c(1:10), date = c(20130101, 20130101, 20130101, 20130101, 20130101, 20130101, 20130101, 20130101, 20130101, 20130101), Number = rnorm(10))
  # The single line command works fine. 
  testdat[, date := as.Date(as.character(date),"%Y%m%d") - 1][, Number:= NULL]
  # But if I wrote them into a function, it failed. 
  # ( In this case, it worked as well.. So I got totally lost. ) 
  test2 &lt;- data.frame(ID = c(1:10), date = c(20130101, 20130101, 20130101, 20130101, 20130101, 20130101, 20130101, 20130101, 20130101, 20130101), Number = rnorm(10))
  readdata &lt;- function(fn){
        DT &lt;- data.table(fn)
        DT[, date:= as.Date(as.character(date),"%Y%m%d") - 1][, Number:= NULL]
        return(DT)
  }
  </code></pre>
  
  <p>To better description, I put parts of my original code here. So you may understand where goes wrong.</p>
  
  <pre><code>readdata &lt;- function(fn){
     DT &lt;- fread(fn, sep=",")
     # DT &lt;- fread("1202.txt")
     setnames(DT, paste0("V",c(1:12)), column_names)
     # Modification on date
     setkey(DT,uid)
     DT[,date := as.Date(as.character(date),"%Y%m%d") - 1][, ignore:= NULL] #ignore is the name of one column
  ...}
  </code></pre>
  
  <p>I have a list of txt files, and I want to do the calculation for each of them. First step is using fread, and proceed one by one. Suppose now the I want to do the calculation based on "1202.txt" file.  If I start from <code>DT &lt;- fread("1202.txt")</code> and then proceeded. It will not come up this error.</p>
  
  <p>If I want to use <code>readdata("1202.txt")</code>
  the error message comes out. 
  Most weird is that, I used the <code>readdata</code> before without any errors.</p>
  
  <p>So what's going on here? Any suggestions? Thanks.</p>
  
  <pre><code>&gt; sessionInfo()
  R version 3.0.2 (2013-09-25)
  Platform: x86_64-w64-mingw32/x64 (64-bit)
  
  locale:
  [1] LC_COLLATE=English_United States.1252 
  [2] LC_CTYPE=English_United States.1252   
  [3] LC_MONETARY=English_United States.1252
  [4] LC_NUMERIC=C                          
  [5] LC_TIME=English_United States.1252    
  
  attached base packages:
  [1] stats     graphics  grDevices utils     datasets  methods   base     
  
  other attached packages:
  [1] data.table_1.8.11
  
  loaded via a namespace (and not attached):
  [1] tools_3.0.2
  </code></pre>
  
  <p><strong>EDIT</strong> </p>
  
  <p>After some trials, I found that if I modified code as the following, it worked</p>
  
  <pre><code>   readdata &lt;- function(fn){
     DT &lt;- fread(fn, sep=",")
     DT &lt;- data.table(DT) ## Just add this line compared to the original one.
     # DT &lt;- fread("1202.txt")
     setnames(DT, paste0("V",c(1:12)), column_names)
     # Modification on date
     setkey(DT,uid)
     DT[,date := as.Date(as.character(date),"%Y%m%d") - 1][, ignore:= NULL] #ignore is the name of one column
  ...}
  </code></pre>
  
  <p>So the error is due to the fread? After fread, it should be a data.table. Why I need to use data.table(DT) to convert it ?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Thanks for attention. Here's an update on Feb 4th, 2014</p>
  
  <p>I first uninstalled my 1.8.11, and followed the instructions of Matt. Install 1.8.10 from CRAN again, and then followed his code step by step. It turns out totally OK without any error.</p>
  
  <p>Then I uninstalled 1.8.11, and then tried to install 1.8.11 again using the precomplied zip file.</p>
  
  <p>As usual, there's a warning message:</p>
  
  <pre><code>&gt; install.packages("~/Desktop/data.table_1.8.11.zip", repos = NULL)
  Warning in install.packages :
  package ~/Desktop/data.table_1.8.11.zip?is not available (for R version 3.0.2)
  Installing package into C:/Users/James/R/win-library/3.0?(as lib?is unspecified)
  package data.table?successfully unpacked and MD5 sums checked
  
  &gt; require(data.table)
  Loading required package: data.table
  data.table 1.8.11  For help type: help("data.table")
  </code></pre>
  
  <p>It seems that the warning message is wrong, it is totally OK when I loaded the package. And at this time, it is totally OK for the whole process. Thanks for the patience of Matt, and Arun, and all other warmhearted ones. I'm a beginner of data.table. And your kindness is really appreciated. </p>
  
  <p>Here's one more thing, as I have already reported in this <a href="https://stackoverflow.com/questions/21219222/documentation-about-melt-data-table-in-data-table">link</a>, and still unsolved. </p>
  
  <pre><code>&gt; ?melt.data.table
  No documentation for 憁elt.data.table?in specified packages and libraries:
  you could try ??melt.data.table?
  </code></pre>
  
  <p>It's really a pity. Any ideas?</p>
  
  <p>I reported my sessionInfo in that link. And I used Win8.1 64bit</p>