1require(data.table) 2# Tests the suppression of := output 3# Since this tests autoprinting at the console, it needs to use the .Rout.save mechanism in R CMD check 4DT = data.table(a=1:2) # Should print at console? 5DT # yes 6DT[1] # yes 7DT[2,a:=3L] # no 8DT # yes 9DT[FALSE,a:=3L] # no 10DT[a==4L,a:=5L] # no 11DT[a %in% 4:8, a:=5L] # no 12DT # yes 13print(DT[2,a:=4L]) # no 14print(DT) # yes 15if (TRUE) DT[2,a:=5L] # no. used to print before v1.9.5 16if (TRUE) if (TRUE) DT[2,a:=6L] # no. used to print before v1.9.5 17(function(){DT[2,a:=5L];NULL})() # print NULL 18DT # no (from v1.9.5+). := suppresses next auto print (can't distinguish just "DT" symbol alone at the prompt) 19DT # yes. 2nd time needed, or solutions below 20(function(){DT[2,a:=5L];NULL})() # print NULL 21DT[] # yes. guaranteed print 22(function(){DT[2,a:=5L];NULL})() # print NULL 23print(DT) # no. only DT[] is guaranteed print from v1.9.6 and R 3.2.0 24(function(){DT[2,a:=5L][];NULL})() # print NULL 25DT # yes. i) function needs to add [] after last one, so that "DT" alone is guaranteed anyway 26(function(){DT[2,a:=5L];DT[];NULL})() # print NULL 27DT # yes. ii) or as a separate DT[] after the last := inside the function 28DT2 = data.table(b=3:4) # no 29(function(){DT[2,a:=6L];DT2[1,b:=7L];NULL})() 30DT # yes. last := was on DT2 not DT 31{DT[2,a:=6L];invisible()} # no 32print(DT) # no 33(function(){print(DT[2,a:=7L]);print(DT);invisible()})() # yes*2 34{print(DT[2,a:=8L]);print(DT);invisible()} # yes*1 Not within function so as at prompt 35DT[1][,a:=9L] # no (was too tricky to detect that DT[1] is a new object). Simple rule is that := always doesn't print 36DT[2,a:=10L][1] # yes 37DT[1,a:=10L][1,a:=10L] # no 38DT[,a:=as.integer(a)] # no 39DT[1,a:=as.integer(a)] # no 40DT[1,a:=10L][] # yes. ...[] == oops, forgot print(...) 41 42# Test that error in := doesn't suppress next valid print, bug #2376 43tryCatch(DT[,foo:=ColumnNameTypo], error=function(e) e$message) # error: not found. 44DT # yes 45DT # yes 46 47