@@ -2273,15 +2273,36 @@ test(753.1, DT[,c("x1","x2"):=4:6, verbose = TRUE], data.table(a=letters[1:3],x=
22732273 output = "RHS for item 2 has been duplicated")
22742274test(753.2, DT[2,x2:=7L], data.table(a=letters[1:3],x=3:1,x1=4:6,x2=c(4L,7L,6L),key="a"))
22752275DT = data.table(a=letters[3:1],x=1:3,y=4:6)
2276- test(754.1 , DT[,c("x1","y1","x2"):=list(x,y)], error="Supplied 3 columns to be assigned 2 items. Please see NEWS for v1.12.2")
2277- test(754.2 , DT[,c("x1","y1","x2"):=list(x,y,x)], data.table(a=letters[3:1],x=1:3,y=4:6,x1=1:3,y1=4:6,x2=1:3))
2276+ test(754.01 , DT[,c("x1","y1","x2"):=list(x,y)], error="Supplied 3 columns to be assigned 2 items. Please see NEWS for v1.12.2")
2277+ test(754.02 , DT[,c("x1","y1","x2"):=list(x,y,x)], data.table(a=letters[3:1],x=1:3,y=4:6,x1=1:3,y1=4:6,x2=1:3))
22782278# And non-recycling i.e. that a single column copy does copy the column
22792279DT = data.table(a=1:3)
2280- test(754.3 , DT[,b:=a][1,a:=4L][2,b:=5L], data.table(a=INT(4,2,3),b=INT(1,5,3)))
2281- test(754.4 , DT[,b:=a][3,b:=6L], data.table(a=INT(4,2,3),b=INT(4,2,6)))
2282- test(754.5 , DT[,a:=as.character (a),verbose=TRUE], output="Direct plonk.*no copy")
2280+ test(754.03 , DT[,b:=a][1,a:=4L][2,b:=5L], data.table(a=INT(4,2,3),b=INT(1,5,3)))
2281+ test(754.04 , DT[,b:=a][3,b:=6L], data.table(a=INT(4,2,3),b=INT(4,2,6)))
2282+ test(754.05 , DT[,a:=as.numeric (a),verbose=TRUE], output="Direct plonk.*no copy")
22832283RHS = as.integer(DT$a)
2284- test(754.6, DT[,a:=RHS,verbose=TRUE], output="RHS for item 1 has been duplicated")
2284+ test(754.06, DT[,a:=RHS,verbose=TRUE], output="RHS for item 1 has been duplicated")
2285+ # Expand ALTREPS in assign.c, #5400
2286+ # String conversion gets deferred
2287+ test(754.07, DT[,a:=as.character(a),verbose=TRUE], output="RHS for item 1 has been duplicated")
2288+ # Executing the code inside of test expands the ALTREP so we repeat the code
2289+ # in order to check the result after a further assignment
2290+ DT = data.table(a=1:3)
2291+ DT[,b:=as.character(a)]
2292+ DT[, a:=5L]
2293+ test(754.08, DT, data.table(a=5L, b=as.character(1:3)))
2294+ # This function returns an ALTREP wrapper if the input is at least length 64
2295+ testFun = function(x) {
2296+ x[FALSE] = 1
2297+ x
2298+ }
2299+ DT = data.table(id=1:64, col1=0, col2=0)
2300+ test(754.09, DT[, col1 := testFun(col2), verbose = TRUE], output="RHS for item 1 has been duplicated")
2301+ DT = data.table(id=1:64, col1=0, col2=0)
2302+ DT[, col1 := testFun(col2)]
2303+ DT[, col2 := 999]
2304+ test(754.10, DT, data.table(id=1:64, col1=0, col2=999))
2305+ rm(testFun)
22852306
22862307# Used to test warning on redundant by (#2282) but by=.EACHI has now superseded
22872308DT = data.table(a=letters[1:3],b=rep(c("d","e"),each=3),x=1:6,key="a,b")
0 commit comments