瀏覽代碼

add live 6

master
flavis 4 年之前
父節點
當前提交
886c71ec07
共有 1 個檔案被更改,包括 27 行新增0 行删除
  1. +27
    -0
      sose2021/r/w06/L06-1.R

+ 27
- 0
sose2021/r/w06/L06-1.R 查看文件

@@ -0,0 +1,27 @@
clear_warnings <- function() last.warning <<- list()

careless <- function(f) {
function(...) {
suppressWarnings(f(...))
}
}

fail_with <- function(expr, value) tryCatch(expr, error = function(cond) value)
does_error <- function(expr) {
didFail <- F
tryCatch(expr, error = function(cond) didFail <<- T)
didFail
}

count_warnings <- function(expr) {
N <- 0
withCallingHandlers(expr, warning = function(cond) N <<- N + 1)
N
}

record <- function(expr) {
msgs <- c()
rec <- function(cond) { msgs <<- c(msgs, cond$message); rlang::cnd_muffle(cond)}
withCallingHandlers(expr, warning = rec, message = rec)
msgs
}

Loading…
取消
儲存