33.pt <- proc.time()
44tryCid <- function (expr ) tryCatch(expr , error = identity )
55tryCmsg <- function (expr ) tryCatch(expr , error = conditionMessage ) # typically == *$message
6- assertErrV <- function (... ) tools :: assertError(... , verbose = TRUE )
6+ assertErrV <- function (... ) tools :: assertError (... , verbose = TRUE )
7+ assertWarnV <- function (... ) tools :: assertWarning(... , verbose = TRUE )
78`%||%` <- function (L , R ) if (is.null(L )) R else L
89# #' get value of `expr` and keep warning as attribute (if there is one)
910getVaW <- function (expr ) {
@@ -464,8 +465,8 @@ mod2 <- local({
464465 offset = { print(" world" ); x - y })
465466}) # rank-deficient in "subtle" way {warning/NA may not be needed}; just show for now:
466467nd <- data.frame (x = 1 : 5 )
467- tools :: assertWarning (print(predict(mod2 , newdata = nd , rankdeficient = " warnif" )))
468- predict(mod2 , newdata = nd , rankdeficient = " NA" )
468+ assertWarnV (print(predict(mod2 , newdata = nd , rankdeficient = " warnif" )))
469+ predict(mod2 , newdata = nd , rankdeficient = " NA" ) # NA's but no warning
469470nm5 <- as.character(1 : 5 )
470471stopifnot(exprs = {
471472 all.equal(setNames(rep(0 , 5 ), nm5 ), predict(mod2 ), tol = 1e-13 ) # pred: 1.776e-15
@@ -507,7 +508,7 @@ stopifnot(all.equal(urf$root, 0.88653, tolerance = 1e-4))
507508
508509
509510# # chkDots() in subset.data.frame() to prevent usage errors
510- tools :: assertWarning (subset(data.frame (y = 1 ), y = 2 ), verbose = TRUE )
511+ assertWarnV (subset(data.frame (y = 1 ), y = 2 ))
511512# # R < 4.3.0 was silent about unused ... arguments
512513
513514
@@ -518,8 +519,8 @@ a <- 1:2
518519assertErrV(a : 1 ) # numerical expression has length > 1
519520assertErrV(2 : a ) # " " " "
520521Sys.unsetenv(" _R_CHECK_LENGTH_COLON_" )
521- tools :: assertWarning (s1 <- a : 1 , verbose = TRUE )
522- tools :: assertWarning (s2 <- 2 : a , verbose = TRUE )
522+ assertWarnV (s1 <- a : 1 )
523+ assertWarnV (s2 <- 2 : a )
523524stopifnot(identical(s1 , 1L ), identical(s2 , 2 : 1 ))
524525Sys.setenv(" _R_CHECK_LENGTH_COLON_" = oldV )# reset
525526# # always only warned in R <= 4.2.z
@@ -802,11 +803,9 @@ km1d <- kappa(m, norm = "1", method = "direct")
802803all.equal(km1d , 7.6 , tol = 0 ) # 1.17e-16 {was wrongly 11.907 in R <= 4.3.1}
803804# # 2) kappa(z, norm="2", LINPACK=TRUE) silently returns estimate of the *1*-norm cond.nr.
804805(km1 <- kappa(m , norm = " 1" )) # 4.651847 {unchanged}
805- tools :: assertWarning(verbose = TRUE , # now *warns*
806- km2L <- kappa(m , norm = " 2" , LINPACK = TRUE ))
806+ assertWarnV( km2L <- kappa(m , norm = " 2" , LINPACK = TRUE )) # now *warns*
807807# # 3) kappa(z, norm="2", LINPACK=FALSE) throws an error
808- tools :: assertWarning(verbose = TRUE , # *same* warning (1-norm instead of 2-)
809- km2La <- kappa(m , norm = " 2" , LINPACK = FALSE ))
808+ assertWarnV(km2La <- kappa(m , norm = " 2" , LINPACK = FALSE ))# same warning (1-norm instead of 2-)
810809km2La
811810# # 4) kappa.qr(z) implicitly assumes nrow(z$qr) >= ncol(z$qr), not true in general
812811(kqrm2 <- kappa(qr(cbind(m , m + 1 ))))
@@ -853,10 +852,8 @@ stopifnot(exprs = {
853852(zm <- m + 1i * c(1 ,- (1 : 2 ))* (m / 4 ))
854853(kz1d <- kappa(zm , norm = " 1" , method = " direct" ))
855854(kz1 <- kappa(zm , norm = " 1" ))# meth = "qr"
856- tools :: assertWarning(verbose = TRUE , # now *warns* {gave *error* previously}
857- kz2L <- kappa(zm , norm = " 2" , LINPACK = TRUE ))
858- tools :: assertWarning(verbose = TRUE , # *same* warning (1-norm instead of 2-)
859- kz2La <- kappa(zm , norm = " 2" , LINPACK = FALSE ))
855+ assertWarnV(kz2L <- kappa(zm , norm = " 2" , LINPACK = TRUE ))# now *warns* {gave *error* previously}
856+ assertWarnV(kz2La <- kappa(zm , norm = " 2" , LINPACK = FALSE ))# same warning (1-norm instead of 2-)
860857kz2La
861858# # 4) kappa.qr(z) implicitly assumes nrow(z$qr) >= ncol(z$qr) ..
862859(kzqr2 <- kappa(qr(cbind(zm , zm + 1 )))) # gave Error .. matrix should be square
@@ -1026,7 +1023,7 @@ stopifnot(identical(tt, drop.terms(tt, dropx = 0[0], keep.response=TRUE)))
10261023
10271024
10281025# # as.complex("<num>i") -- should work (and fail/warn) as the parser does:
1029- tools :: assertWarning( cc <- as.complex(" 12iL" ), verbose = TRUE )
1026+ assertWarnV( cc <- as.complex(" 12iL" ))
10301027tools :: assertWarning(cF <- as.complex(" 12irene" ))
10311028tools :: assertWarning(cI <- as.complex(" 12I" ))
10321029stopifnot(is.na(cc ), is.na(cF ), is.na(cI ),
@@ -1477,6 +1474,8 @@ if(attr(oL, "ok") && capabilities("NLS") && !is.na(.popath)
14771474 stopifnot(is.character(print(" checking 'out' : " )),
14781475 grepl(" ^argument non num.rique pour un " , out ))
14791476# # was *not* switched to French (when this was run via 'make ..')
1477+ # # reset {just in case}:
1478+ Sys.setLanguage(" en" )
14801479
14811480
14821481# # print( ls.str() ) using '<missing>' also in non-English setup:
@@ -1605,9 +1604,9 @@ assertErrV(options(scipen = NULL))# would work (but ..) in R <= 4.4.2
16051604assertErrV(options(scipen = 1 : 2 )) # would just work
16061605assertErrV(options(scipen = 1e99 ))# would "work" w/ 2 warnings and invalid setting
16071606stopifnot(identical(getOption(" scipen" ), scipenO ))# unchanged
1608- tools :: assertWarning( verbose = TRUE , options(scipen = - 100 ))# warns and sets to min = -9
1607+ assertWarnV( options(scipen = - 100 ))# warns and sets to min = -9
16091608stopifnot(identical(getOption(" scipen" ), - 9L ))
1610- tools :: assertWarning( verbose = TRUE , options(scipen = 100000 ))# warns and sets to max = 9999
1609+ assertWarnV( options(scipen = 100000 ))# warns and sets to max = 9999
16111610stopifnot(identical(getOption(" scipen" ), 9999L ))
16121611# # setting to NULL would invalidate as.character(Sys.time())
16131612
@@ -1678,6 +1677,24 @@ sort.int(x, method = "quick")
16781677sort.int(x , method = " quick" , index.return = TRUE )
16791678
16801679
1680+ # # More warning for _illegal_ OutDec -- even auto print() ing now warns when OutDec is illegal:
1681+ assertWarnV(op <- options(OutDec = " _._" , scipen = 6 , warn = 1 ))
1682+ assertWarnV( print(pi ) ) # _new_ warning ... "will become an error"
1683+ writeLines(m <- capture.output(format(pi ), type = " message" ))
1684+ # # Warning in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3L, :
1685+ # # the decimal mark is more than one character wide; this will become an error
1686+ assertWarnV(options(OutDec = " " ))
1687+ m2 <- tryCatch(print(pi ), warning = conditionMessage )
1688+ assertWarnV( print(pi * 10 ^ (- 4 : 4 )) ) # _new_ warning
1689+ if (englishMsgs ) stopifnot(exprs = {
1690+ grepl(" ^Warning in prettyNum\\ (\\ .Internal\\ (format\\ (" , m [1 ])
1691+ grepl(" the decimal mark is more than one character wide" , m [length(m )])
1692+ grepl(" the decimal mark is less than one character wide" , m2 )
1693+ })
1694+ # # now warn from format() and (only once) from print()
1695+ options(op ) # return to sanity + warn=2
1696+
1697+
16811698
16821699# # keep at end
16831700rbind(last = proc.time() - .pt ,
0 commit comments