R Under development (unstable) (2026-10-28 r90783 ucrt) -- "Unsuffered Consequences" Copyright (C) 2026 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 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. > library(BATTS) > expect_reject <- function(expr, pattern) { + before <- .Random.seed + error <- tryCatch({force(expr); NA_character_}, error=conditionMessage) + stopifnot(!is.na(error), grepl(pattern,error,fixed=TRUE), identical(before,.Random.seed)) + } > set.seed(22023) > x <- matrix(rnorm(48),24,2); g <- rep(0:1,each=12) > for (bad in list(-1,NA_real_,NaN,Inf,-Inf,1.5,numeric(),c(0,1),TRUE,'0',2^31,matrix(0))) + expect_reject(batts(x,g,size_backfitting=4,size_burnin=bad), 'size_burnin must') Warning message: batts() is deprecated; use batts_bart() instead (see ?`BATTS-deprecated`). batts() still works and gives the same result. This warning is shown once per session. > for (bad in list(0,-1,NA_real_,Inf,1.5,numeric(),c(1,2),TRUE,'4',2^31,matrix(4))) + expect_reject(batts(x,g,size_backfitting=bad), 'size_backfitting must') > bad_moves <- list(c(.8,.8,.8),c(.2,.2,.2),c(-.1,.5,.6),c(0,.5,.5),c(.5,.5), + c(1,1,1,1)/4,c(NA,.5,.5),c(Inf,.5,.5),numeric(),TRUE,c('a','b','c'),matrix(1/3,1,3)) > for (bad in bad_moves) + expect_reject(batts(x,g,size_backfitting=4,prob_moves=bad), 'prob_moves must') > native <- function(burn=0L, moves=c(1/3,1/3,1/3), draws=4L) + BATTS:::run_adaboost(x,g,2L,0L,.01,c(.25,.5,.75),rep(1L,24),1,1e-100,FALSE, + burn,draws,1L,moves,5,1,1,.95,2,FALSE,TRUE,matrix(0L,0,0)) > expect_reject(native(burn=-1L),'size_burnin must') > expect_reject(native(burn=NA_integer_),'size_burnin must') > expect_reject(native(draws=-1L),'size_backfitting must') > for (bad in bad_moves[1:9]) expect_reject(native(moves=bad),'prob_moves must') > for (burn in c(0L,3L)) for (moves in list(c(1/3,1/3,1/3),c(.2,.5,.3))) { + fit <- batts(x,g,num_trees=2,size_backfitting=4,size_burnin=burn,prob_moves=moves,quiet=TRUE) + stopifnot(identical(dim(fit$balance_weight_BART_data),c(24L,4L)), + all(is.finite(fit$balance_weight_BART_data)),all(fit$balance_weight_BART_data>0)) + } > # MH grow/prune corrections are reciprocals for asymmetric valid probabilities. > m <- c(.2,.5,.3) > stopifnot(identical(log(m[2])-log(m[1]),-(log(m[1])-log(m[2])))) > cat('U22/U23 invalid-input rejection, RNG preservation and valid-input checks passed.\n') U22/U23 invalid-input rejection, RNG preservation and valid-input checks passed. > > proc.time() user system elapsed 0.26 0.06 0.31