Aliases: warnErrList
### ** Examples ## Regression for each Chick: ChWtgrps <- split(ChickWeight, ChickWeight[,"Chick"]) sapply(ChWtgrps, nrow)# typically 12 obs.
18 16 15 13 9 20 10 8 17 19 4 6 11 3 1 12 2 5 14 7 24 30 22 23 27 28 2 7 8 12 12 12 12 11 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 26 25 29 21 33 37 36 31 39 38 32 40 34 35 44 45 43 41 47 49 46 50 42 48 12 12 12 12 12 12 12 12 12 12 12 12 12 12 10 12 12 12 12 12 12 12 12 12
nlis1 <- lapply(ChWtgrps, function(DAT) tryCatch(error = identity, lm(weight ~ (Time + I(Time^2)) * Diet, data = DAT))) nl1 <- warnErrList(nlis1) #-> warning :
Warning: 50 times caught the same error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
## 50 times the same error (as Diet has only one level in each group) stopifnot(sapply(nl1, is.null)) ## all errors --> all replaced by NULL nlis2 <- lapply(ChWtgrps, function(DAT) tryCatch(error = identity, lm(weight ~ Time + I(Time^2), data = DAT))) nl2 <- warnErrList(nlis2) stopifnot(identical(nl2, nlis2)) # because there was *no* error at all nlis3 <- lapply(ChWtgrps, function(DAT) tryCatch(error = identity, lm(weight ~ poly(Time, 3), data = DAT))) nl3 <- warnErrList(nlis3) # 1 error caught:
Warning: 1 error caught in poly(Time, 3): 'degree' must be less than number of unique points
stopifnot(inherits(nlis3[[1]], "error") , identical(nl3[-1], nlis3[-1]) , is.null(nl3[[1]]) ) ## With different error messages if(requireNamespace("nlme")) { # almost always, as it is recommended data(Soybean, package="nlme") attr(Soybean, "formula") #-> weight ~ Time | Plot => split by "Plot": L <- lapply(split(Soybean, Soybean[,"Plot"]), function(DD) tryCatch(error = identity, nls(weight ~ SSlogis(Time, Asym, xmid, scal), data = DD))) Lw <- warnErrList(L) } # if <nlme>
Warning: 2 errors caught in nls(y ~ 1/(1 + exp((xmid - x)/scal)), data = xy, start = list(xmid = aux[[1L]], scal = aux[[2L]]), algorithm = "plinear", ...). The error messages and their frequencies are number of iterations exceeded maximum of 50 1 step factor 0.000488281 reduced below 'minFactor' of 0.000976562 1