title: [.data.table (merge - X[Y]) key got lost in v.1.9.3
body: <p>I have 2 data.tables <code>dtp</code> and <code>dtab</code>.</p>
  
  <pre><code>require(data.table)
  set.seed(1)
  dtp &lt;- data.table(pid = gl(3, 3, labels = c("du", "i", "nouana")),
                    year = gl(3, 1, 9, labels = c("2007", "2010", "2012")),
                    val = rnorm(9), key = c("pid", "year"))
  dtab &lt;- data.table(pid = factor(c("i", "nouana")),
                    year = factor(c("2010", "2000")),
                    abn = sample(1:5, 2, replace = TRUE), key =
                     c("pid", "year"))
  dtp
  ##       pid year        val
  ## 1:     du 2007 -0.6264538
  ## 2:     du 2010  0.1836433
  ## 3:     du 2012 -0.8356286
  ## 4:      i 2007  1.5952808
  ## 5:      i 2010  0.3295078
  ## 6:      i 2012 -0.8204684
  ## 7: nouana 2007  0.4874291
  ## 8: nouana 2010  0.7383247
  ## 9: nouana 2012  0.5757814
  
  dtab
  ##       pid year abn
  ## 1:      i 2010   2
  ## 2: nouana 2000   4
  </code></pre>
  
  <p>If i merge them using <code>[.data.table</code>, the key get lost:</p>
  
  <pre><code>dtp[dtab]
  ##       pid year       val abn
  ## 1:      i 2010 0.3295078   2
  ## 2: nouana 2000        NA   4
  
  key(dtp[dtab]) # key got lost
  ## NULL # v.1.9.3
  
  ##### which was in 1.8.10
  ## [1] "pid"  "year"
  </code></pre>
  
  <p>Ok, for this case I can set it manually:</p>
  
  <pre><code>res1 &lt;- setkeyv(dtp[dtab], key(dtp))
  res1
  ##       pid year       val abn
  ## 1:      i 2010 0.3295078   2
  ## 2: nouana 2000        NA   4
  
  key(res1) # repaired it
  ## [1] "pid"  "year"
  </code></pre>
  
  <h2>Question:</h2>
  
  <p>Is this the wanted behaviour, or is it a bug?</p>
  
  <h2>Alternative:</h2>
  
  <p>Using the <code>merge</code> syntax does what I expected:</p>
  
  <pre><code>merge(dtp, dtab, all.y = TRUE)
  ##       pid year       val abn
  ## 1:      i 2010 0.3295078   2
  ## 2: nouana 2000        NA   4
  
  key(merge(dtp, dtab, all.y = TRUE)) # everything ok
  ## [1] "pid"  "year"
  </code></pre>
  
  <h2>Usage: add a column:</h2>
  
  <p>If I want to merge the column <code>abn</code> from <code>dtab</code> to <code>dtp</code> there is one easy possibility to write <code>dtab[dtp]</code> loosing the key and the order of the columns:</p>
  
  <pre><code>dtab[dtp]
  ##       pid year abn        val
  ## 1:     du 2007  NA -0.6264538
  ## 2:     du 2010  NA  0.1836433
  ## 3:     du 2012  NA -0.8356286
  ## 4:      i 2007  NA  1.5952808
  ## 5:      i 2010   2  0.3295078
  ## 6:      i 2012  NA -0.8204684
  ## 7: nouana 2007  NA  0.4874291
  ## 8: nouana 2010  NA  0.7383247
  ## 9: nouana 2012  NA  0.5757814
  </code></pre>
  
  <h2>Example how it could work</h2>
  
  <p>If there would be other cols in <code>dtab</code>, but just <code>abn</code> should be merged there is another possibility (my favourite):</p>
  
  <pre><code>##### just show it:
  ## dtp[dtab[dtp, abn]] # v.1.8.10
  
  dtp[dtab[dtp, abn, by = .EACHI]] # since v.1.9.3
  ##       pid year        val abn
  ## 1:     du 2007 -0.6264538  NA
  ## 2:     du 2010  0.1836433  NA
  ## 3:     du 2012 -0.8356286  NA
  ## 4:      i 2007  1.5952808  NA
  ## 5:      i 2010  0.3295078   2
  ## 6:      i 2012 -0.8204684  NA
  ## 7: nouana 2007  0.4874291  NA
  ## 8: nouana 2010  0.7383247  NA
  ## 9: nouana 2012  0.5757814  NA
  </code></pre>
  
  <p>or assign it:</p>
  
  <pre><code>dtp[dtab[dtp], abn := abn] # assign it
  
  dtp
  ##       pid year        val abn
  ## 1:     du 2007 -0.6264538  NA
  ## 2:     du 2010  0.1836433  NA
  ## 3:     du 2012 -0.8356286  NA
  ## 4:      i 2007  1.5952808  NA
  ## 5:      i 2010  0.3295078   2
  ## 6:      i 2012 -0.8204684  NA
  ## 7: nouana 2007  0.4874291  NA
  ## 8: nouana 2010  0.7383247  NA
  ## 9: nouana 2012  0.5757814  NA
  
  key(dtp) # ok
  ## [1] "pid"  "year"
  </code></pre>
  
  <p>In latter cases (show or assign) the key survives.</p>
  
  <p>@<a href="https://stackoverflow.com/users/559784/arun">Arun</a>: Here is the <code>sessionInfo()</code>:</p>
  
  <pre><code>sessionInfo()
  ## R version 3.1.0 (2014-04-10)
  ## Platform: powerpc64-unknown-linux-gnu (64-bit)
  
  ## locale:
  ##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
  ##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
  ##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
  ##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
  ##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
  ## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
  
  ## attached base packages:
  ## [1] stats     graphics  grDevices utils     datasets  methods   base     
  
  ## other attached packages:
  ## [1] data.table_1.9.3
  
  ## loaded via a namespace (and not attached):
  ## [1] plyr_1.8       reshape2_1.2.2 stringr_0.6.2
  </code></pre>