@@ -154,13 +154,11 @@ test(4.24, colnamesInt(dt, "a"), error="has no names")
154154
155155# verbose
156156dt = data.table(a=c(1L, 2L, NA_integer_), b=c(1, 2, NA_real_))
157- old=options(datatable.verbose=TRUE)
158- test(5.01, nafill(dt, "locf"), output="nafillInteger: took.*nafillDouble: took.*nafillR.*took")
159- test(5.02, setnafill(dt, "locf"), output="nafillInteger: took.*nafillDouble: took.*nafillR.*took")
157+ test(5.01, options = c(datatable.verbose = TRUE), nafill(dt, "locf"), output="nafillInteger: took.*nafillDouble: took.*nafillR.*took")
158+ test(5.02, options = c(datatable.verbose = TRUE), setnafill(dt, "locf"), output="nafillInteger: took.*nafillDouble: took.*nafillR.*took")
160159if (test_bit64) {
161- test(5.03, nafill(as.integer64(c(NA,2,NA,3)), "locf"), as.integer64(c(NA,2,2,3)), output="nafillInteger64: took.*nafillR.*took")
160+ test(5.03, options = c(datatable.verbose = TRUE), nafill(as.integer64(c(NA,2,NA,3)), "locf"), as.integer64(c(NA,2,2,3)), output="nafillInteger64: took.*nafillR.*took")
162161}
163- options(old)
164162
165163# coerceAs int/numeric/int64 as used in nafill
166164if (test_bit64) {
@@ -243,65 +241,61 @@ if (test_bit64) {
243241}
244242
245243# coerceAs verbose
246- options(datatable.verbose=2L)
247244input = 1
248- test(10.01, ans<-coerceAs(input, 1), 1, output="double[numeric] into double[numeric]")
249- test(10.02, address(input)!=address(ans))
250- test(10.03, ans<-coerceAs(input, 1, copy=FALSE), 1, output="copy=false and input already of expected type and class double[numeric]")
251- test(10.04, address(input), address(ans))
252- test(10.05, ans<-coerceAs(input, 1L), 1L, output="double[numeric] into integer[integer]")
253- test(10.06, address(input)!=address(ans))
254- test(10.07, ans<-coerceAs(input, 1L, copy=FALSE), 1L, output="double[numeric] into integer[integer]", notOutput="copy=false")
255- test(10.08, address(input)!=address(ans))
256- test(10.09, coerceAs("1", 1L), 1L, output="character[character] into integer[integer]", warning="Coercing.*character.*integer")
257- test(10.10, coerceAs("1", 1), 1, output="character[character] into double[numeric]", warning="Coercing.*character.*double")
258- test(10.11, coerceAs("a", factor("x")), factor("a", levels=c("x","a")), output="character[character] into integer[factor]") ## levels of 'as' are retained!
259- test(10.12, coerceAs("a", factor()), factor("a"), output="character[character] into integer[factor]")
260- test(10.13, coerceAs(1, factor("x")), factor("x"), output="double[numeric] into integer[factor]")
261- test(10.14, coerceAs(1, factor("x", levels=c("x","y"))), factor("x", levels=c("x","y")), output="double[numeric] into integer[factor]")
262- test(10.15, coerceAs(2, factor("x", levels=c("x","y"))), factor("y", levels=c("x","y")), output="double[numeric] into integer[factor]")
263- test(10.16, coerceAs(1:2, factor(c("x","y"))), factor(c("x","y")), output="integer[integer] into integer[factor]")
264- test(10.17, coerceAs(1:3, factor(c("x","y"))), output="integer[integer] into integer[factor]", error="factor numbers.*3 is outside the level range")
265- test(10.18, coerceAs(c(1,2,3), factor(c("x","y"))), output="double[numeric] into integer[factor]", error="factor numbers.*3.000000 is outside the level range")
266- test(10.19, coerceAs(factor("x"), factor(c("x","y"))), factor("x", levels=c("x","y")), output="integer[factor] into integer[factor]")
267- test(10.20, coerceAs(factor("x"), factor(c("x","y")), copy=FALSE), factor("x", levels=c("x","y")), output="input already of expected type and class") ## copy=F has copyMostAttrib
245+ test(10.01, options = c(datatable.verbose = 2L), ans<-coerceAs(input, 1), 1, output="double[numeric] into double[numeric]")
246+ test(10.02, options = c(datatable.verbose = 2L), address(input)!=address(ans))
247+ test(10.03, options = c(datatable.verbose = 2L), ans<-coerceAs(input, 1, copy=FALSE), 1, output="copy=false and input already of expected type and class double[numeric]")
248+ test(10.04, options = c(datatable.verbose = 2L), address(input), address(ans))
249+ test(10.05, options = c(datatable.verbose = 2L), ans<-coerceAs(input, 1L), 1L, output="double[numeric] into integer[integer]")
250+ test(10.06, options = c(datatable.verbose = 2L), address(input)!=address(ans))
251+ test(10.07, options = c(datatable.verbose = 2L), ans<-coerceAs(input, 1L, copy=FALSE), 1L, output="double[numeric] into integer[integer]", notOutput="copy=false")
252+ test(10.08, options = c(datatable.verbose = 2L), address(input)!=address(ans))
253+ test(10.09, options = c(datatable.verbose = 2L), coerceAs("1", 1L), 1L, output="character[character] into integer[integer]", warning="Coercing.*character.*integer")
254+ test(10.10, options = c(datatable.verbose = 2L), coerceAs("1", 1), 1, output="character[character] into double[numeric]", warning="Coercing.*character.*double")
255+ test(10.11, options = c(datatable.verbose = 2L), coerceAs("a", factor("x")), factor("a", levels=c("x","a")), output="character[character] into integer[factor]") ## levels of 'as' are retained!
256+ test(10.12, options = c(datatable.verbose = 2L), coerceAs("a", factor()), factor("a"), output="character[character] into integer[factor]")
257+ test(10.13, options = c(datatable.verbose = 2L), coerceAs(1, factor("x")), factor("x"), output="double[numeric] into integer[factor]")
258+ test(10.14, options = c(datatable.verbose = 2L), coerceAs(1, factor("x", levels=c("x","y"))), factor("x", levels=c("x","y")), output="double[numeric] into integer[factor]")
259+ test(10.15, options = c(datatable.verbose = 2L), coerceAs(2, factor("x", levels=c("x","y"))), factor("y", levels=c("x","y")), output="double[numeric] into integer[factor]")
260+ test(10.16, options = c(datatable.verbose = 2L), coerceAs(1:2, factor(c("x","y"))), factor(c("x","y")), output="integer[integer] into integer[factor]")
261+ test(10.17, options = c(datatable.verbose = 2L), coerceAs(1:3, factor(c("x","y"))), output="integer[integer] into integer[factor]", error="factor numbers.*3 is outside the level range")
262+ test(10.18, options = c(datatable.verbose = 2L), coerceAs(c(1,2,3), factor(c("x","y"))), output="double[numeric] into integer[factor]", error="factor numbers.*3.000000 is outside the level range")
263+ test(10.19, options = c(datatable.verbose = 2L), coerceAs(factor("x"), factor(c("x","y"))), factor("x", levels=c("x","y")), output="integer[factor] into integer[factor]")
264+ test(10.20, options = c(datatable.verbose = 2L), coerceAs(factor("x"), factor(c("x","y")), copy=FALSE), factor("x", levels=c("x","y")), output="input already of expected type and class") ## copy=F has copyMostAttrib
268265a = structure("a", class="a")
269266b = structure("b", class="b")
270- test(10.21, coerceAs(a, b), structure("a", class="b"), output="character[a] into character[b]")
267+ test(10.21, options = c(datatable.verbose = 2L), coerceAs(a, b), structure("a", class="b"), output="character[a] into character[b]")
271268a = structure(1L, class="a")
272269b = structure(2L, class="b")
273- test(10.22, coerceAs(a, b), structure(1L, class="b"), output="integer[a] into integer[b]")
270+ test(10.22, options = c(datatable.verbose = 2L), coerceAs(a, b), structure(1L, class="b"), output="integer[a] into integer[b]")
274271a = structure(1, class="a")
275272b = structure(2, class="b")
276- test(10.23, coerceAs(a, b), structure(1, class="b"), output="double[a] into double[b]")
273+ test(10.23, options = c(datatable.verbose = 2L), coerceAs(a, b), structure(1, class="b"), output="double[a] into double[b]")
277274a = structure(1, class="a")
278275b = structure(2L, class="b")
279- test(10.24, coerceAs(a, b), structure(1L, class="b"), output="double[a] into integer[b]")
276+ test(10.24, options = c(datatable.verbose = 2L), coerceAs(a, b), structure(1L, class="b"), output="double[a] into integer[b]")
280277if (test_bit64) {
281278 x = as.integer64(1L)
282- test(10.81, coerceAs(x, 1), 1, output="double[integer64] into double[numeric]")
283- test(10.82, coerceAs(x, 1L), 1L, output="double[integer64] into integer[integer]")
284- test(10.83, coerceAs(x, "1"), "1", output="double[integer64] into character[character]")
285- test(10.84, coerceAs(1, x), x, output="double[numeric] into double[integer64]")
286- test(10.85, coerceAs(1L, x), x, output="integer[integer] into double[integer64]")
287- test(10.86, coerceAs("1", x), x, output="character[character] into double[integer64]", warning="Coercing.*character")
288- options(datatable.verbose=3L)
289- test(10.87, coerceAs(x, 1L), 1L, output=c("double[integer64] into integer[integer]","Zero-copy coerce when assigning 'integer64' to 'integer'"))
290- test(10.88, coerceAs(1L, x), x, output=c("integer[integer] into double[integer64]","Zero-copy coerce when assigning 'integer' to 'integer64'"))
291- options(datatable.verbose=2L)
292- test(10.89, coerceAs(-2147483649, x), as.integer64(-2147483649), output="double[numeric] into double[integer64]")
279+ test(10.81, options = c(datatable.verbose = 2L), coerceAs(x, 1), 1, output="double[integer64] into double[numeric]")
280+ test(10.82, options = c(datatable.verbose = 2L), coerceAs(x, 1L), 1L, output="double[integer64] into integer[integer]")
281+ test(10.83, options = c(datatable.verbose = 2L), coerceAs(x, "1"), "1", output="double[integer64] into character[character]")
282+ test(10.84, options = c(datatable.verbose = 2L), coerceAs(1, x), x, output="double[numeric] into double[integer64]")
283+ test(10.85, options = c(datatable.verbose = 2L), coerceAs(1L, x), x, output="integer[integer] into double[integer64]")
284+ test(10.86, options = c(datatable.verbose = 2L), coerceAs("1", x), x, output="character[character] into double[integer64]", warning="Coercing.*character")
285+ test(10.87, options = c(datatable.verbose = 3L), coerceAs(x, 1L), 1L, output=c("double[integer64] into integer[integer]","Zero-copy coerce when assigning 'integer64' to 'integer'"))
286+ test(10.88, options = c(datatable.verbose = 3L), coerceAs(1L, x), x, output=c("integer[integer] into double[integer64]","Zero-copy coerce when assigning 'integer' to 'integer64'"))
287+ test(10.89, options = c(datatable.verbose = 2L), coerceAs(-2147483649, x), as.integer64(-2147483649), output="double[numeric] into double[integer64]")
293288}
294289if (test_nanotime) {
295290 x = nanotime(1L)
296- test(10.91, coerceAs(x, 1), 1, output="double[nanotime] into double[numeric]")
297- test(10.92, coerceAs(x, 1L), 1L, output="double[nanotime] into integer[integer]")
298- test(10.93, substring(coerceAs(x, "1"),1,11) %in% c("1","1970-01-01T"), output="double[nanotime] into character[character]")
299- # ^ https://github.com/eddelbuettel/nanotime/issues/92; %in% so as not to break if nanotime adds as.character method
300- test(10.94, coerceAs(1, x), x, output="double[numeric] into double[nanotime]")
301- test(10.95, coerceAs(1L, x), x, output="integer[integer] into double[nanotime]")
302- test(10.96, coerceAs("1", x), x, output="character[character] into double[nanotime]", warning="Coercing.*character")
291+ test(10.91, options = c(datatable.verbose = 2L), coerceAs(x, 1), 1, output="double[nanotime] into double[numeric]")
292+ test(10.92, options = c(datatable.verbose = 2L), coerceAs(x, 1L), 1L, output="double[nanotime] into integer[integer]")
293+ test(10.93, options = c(datatable.verbose = 2L), substring(coerceAs(x, "1"),1,11) %in% c("1","1970-01-01T"), output="double[nanotime] into character[character]")
294+ # ^ https://github.com/eddelbuettel/nanotime/issues/92; %in% so as not to break if nanotime adds as.character method
295+ test(10.94, options = c(datatable.verbose = 2L), coerceAs(1, x), x, output="double[numeric] into double[nanotime]")
296+ test(10.95, options = c(datatable.verbose = 2L), coerceAs(1L, x), x, output="integer[integer] into double[nanotime]")
297+ test(10.96, options = c(datatable.verbose = 2L), coerceAs("1", x), x, output="character[character] into double[nanotime]", warning="Coercing.*character")
303298}
304- options(datatable.verbose=FALSE)
305299test(11.01, coerceAs(list(a=1), 1), error="is not atomic")
306300test(11.02, coerceAs(1, list(a=1)), list(1))
307301test(11.03, coerceAs(sum, 1), error="is not atomic")
@@ -328,7 +322,4 @@ test(11.09, coerceAs(1L, a), error="must not be matrix or array")
328322test(99.1, data.table(a=1,b=2)[1,1, verbose=1], error="verbose must be logical or integer")
329323test(99.2, data.table(a=1,b=2)[1,1, verbose=1:2], error="verbose must be length 1 non-NA")
330324test(99.3, data.table(a=1,b=2)[1,1, verbose=NA], error="verbose must be length 1 non-NA")
331- options(datatable.verbose=1)
332- test(99.4, coerceAs(1, 2L), error="verbose option must be length 1 non-NA logical or integer")
333- options(datatable.verbose=FALSE)
334-
325+ test(99.4, options = c(datatable.verbose = 1), coerceAs(1, 2L), error="verbose option must be length 1 non-NA logical or integer")
0 commit comments