
R version 3.1.1 (2014-07-10) -- "Sock it to Me"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> require(data.table)
Loading required package: data.table
> # Tests the suppression of := output
> # Since this tests autoprinting at the console, it needs to use the .Rout.save mechanism in R CMD check
> DT = data.table(a=1:2)                # Should print at console?
> DT                                    # yes
   a
1: 1
2: 2
> DT[1]                                 # yes
   a
1: 1
> DT[2,a:=3L]                           # no
> DT                                    # yes
   a
1: 1
2: 3
> DT[FALSE,a:=3L]                       # no
> DT[a==4L,a:=5L]                       # no
> DT[a %in% 4:8, a:=5L]                 # no
> DT                                    # yes
   a
1: 1
2: 3
> print(DT[2,a:=4L])                    # no
> print(DT)                             # yes
   a
1: 1
2: 4
> if (TRUE) DT[2,a:=5L]                 # no. used to print before v1.9.5
> if (TRUE) if (TRUE) DT[2,a:=6L]       # no. used to print before v1.9.5
> (function(){DT[2,a:=5L];NULL})()      # print NULL
NULL
> DT                                    # no (from v1.9.5+). := suppresses next auto print (can't distinguish just "DT" symbol alone at the prompt)
> DT                                    # yes. 2nd time needed, or solutions below
   a
1: 1
2: 5
> (function(){DT[2,a:=5L];NULL})()      # print NULL
NULL
> DT[]                                  # yes. guaranteed print
   a
1: 1
2: 5
> (function(){DT[2,a:=5L];NULL})()      # print NULL
NULL
> print(DT)                             # no. only DT[] is guaranteed print from v1.9.6 and R 3.2.0
> (function(){DT[2,a:=5L][];NULL})()    # print NULL
NULL
> DT                                    # yes. i) function needs to add [] after last one, so that "DT" alone is guaranteed anyway
   a
1: 1
2: 5
> (function(){DT[2,a:=5L];DT[];NULL})() # print NULL
NULL
> DT                                    # yes. ii) or as a separate DT[] after the last := inside the function
   a
1: 1
2: 5
> DT2 = data.table(b=3:4)               # no
> (function(){DT[2,a:=6L];DT2[1,b:=7L];NULL})()
NULL
> DT                                    # yes. last := was on DT2 not DT
   a
1: 1
2: 6
> {DT[2,a:=6L];invisible()}             # no
> print(DT)                             # no
> (function(){print(DT[2,a:=7L]);print(DT);invisible()})()    # yes*2
   a
1: 1
2: 7
   a
1: 1
2: 7
> {print(DT[2,a:=8L]);print(DT);invisible()}                  # yes*1  Not within function so as at prompt
   a
1: 1
2: 8
> DT[1][,a:=9L]      # no (was too tricky to detect that DT[1] is a new object). Simple rule is that := always doesn't print
> DT[2,a:=10L][1]                       # yes
   a
1: 1
> DT[1,a:=10L][1,a:=10L]                # no
> DT[,a:=as.integer(a)]                 # no
> DT[1,a:=as.integer(a)]                # no
> DT[1,a:=10L][]                        # yes. ...[] == oops, forgot print(...)
    a
1: 10
2: 10
> 
> # Test that error in := doesn't suppress next valid print, bug #2376
> tryCatch(DT[,foo:=ColumnNameTypo], error=function(e) e$message)         # error: not found.
[1] "object 'ColumnNameTypo' not found"
> DT                                    # yes
    a
1: 10
2: 10
> DT                                    # yes
    a
1: 10
2: 10
> 
> 
> proc.time()
   user  system elapsed 
   3.14    0.10    3.22 
