The R Project SVN R

Rev

Rev 89698 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 89698 Rev 89843
Line 188... Line 188...
188
    !is.mts(structure(numeric(), class = "mts"))
188
    !is.mts(structure(numeric(), class = "mts"))
189
    !is.mts(structure(numeric(), class = c("mts", "ts", "matrix")))
189
    !is.mts(structure(numeric(), class = c("mts", "ts", "matrix")))
190
})
190
})
191
## is.mts() was too simplistic in R <= 4.2.x
191
## is.mts() was too simplistic in R <= 4.2.x
192
 
192
 
-
 
193
assertErrV  <- function(...) tools::assertError  (..., verbose=TRUE)
-
 
194
assertWarnV <- function(...) tools::assertWarning(..., verbose=TRUE)
-
 
195
identical3 <- function(a,b,c)   identical(a,b) && identical(b,c)
-
 
196
identical4 <- function(a,b,c,d) identical(a,b) && identical3(b,c,d)
-
 
197
##' get value of `expr` and keep warning as attribute (if there is one)
-
 
198
getVaW <- function(expr, obj=FALSE) {
-
 
199
    W <- NULL
-
 
200
    withCallingHandlers(val <- expr,
-
 
201
                        warning = function(w) {
-
 
202
                            W <<- if(obj) w else conditionMessage(w)
-
 
203
                            invokeRestart("muffleWarning") })
-
 
204
    structure(val %||% quote(._NULL_()), warning = W) # NULL cannot have attr.
-
 
205
}
-
 
206
##
-
 
207
onWindows <- .Platform$OS.type == "windows"
-
 
208
englishMsgs <- {
-
 
209
    ## 1. LANGUAGE takes precedence over locale settings:
-
 
210
    if(nzchar(lang <- Sys.getenv("LANGUAGE")))
-
 
211
        lang == "en"
-
 
212
    else { ## 2. Query the  locale
-
 
213
        if(!onWindows) {
-
 
214
            ## sub() :
-
 
215
            lc.msgs <- sub("\\..*", "", print(Sys.getlocale("LC_MESSAGES")))
-
 
216
            lc.msgs == "C" || substr(lc.msgs, 1,2) == "en"
-
 
217
        } else { ## Windows
-
 
218
            lc.type <- sub("\\..*", "", sub("_.*", "", print(Sys.getlocale("LC_CTYPE"))))
-
 
219
            lc.type == "English" || lc.type == "C"
-
 
220
        }
-
 
221
    }
-
 
222
}
-
 
223
cat(sprintf("English messages: %s\n", englishMsgs))
-
 
224
options(warn = 2, # only caught or asserted warnings
-
 
225
        width = 99) # instead of 80
-
 
226
 
-
 
227
## More Ops.ts() cases
-
 
228
m2 <- matrix(1:12, 6,2)
-
 
229
str(tm <- ts(m2))
-
 
230
typeof(tm.7 <- ts(m2,   start = 7)) # integer
-
 
231
typeof(tmd7 <- ts(m2+0, start = 7)) # double
-
 
232
typeof(td2 <- (tm+0) + tm) # d
-
 
233
assertErrV(tm + ts(matrix(1:12, 6,3))) # non-conformable
-
 
234
   (r  <- getVaW(tm  + tm.7)) # all three r* are 0 x 2 matrices
-
 
235
str(rd.<- getVaW(tm.7+ (tm+0)))
-
 
236
    rd <- getVaW(tm  + tmd7)
-
 
237
stopifnot(exprs = {
-
 
238
    identical4(c(0L, 2L), dim(r), dim(rd), dim(rd.))
-
 
239
    is.character(w <- attr(r,  "warning"))
-
 
240
    !englishMsgs || w == "non-intersecting series"
-
 
241
    identical3(w, attr(rd, "warning"), attr(rd., "warning"))
-
 
242
    is.integer(r) # as tm and tm.7
-
 
243
    is.double(rd.)# *not* true in R <= 4.5.3
-
 
244
    is.double(rd) # (neither)
-
 
245
    is.double(td2)
-
 
246
})
-
 
247
##
-
 
248
 
193
 
249
 
194
 
250
 
195
cat('Time elapsed: ', proc.time() - .proctime00,'\n')
251
cat('Time elapsed: ', proc.time() - .proctime00,'\n')